我需要以 utf-8 编码显示文字。
echo "sometext1 ${DATA[1]} \
sometext2 ${DATA[2]} \
sometext3 ${DATA[3]} \
sometext4 ${DATA[4]} \
sometext5 ${DATA[5]}"
我尝试执行以下操作:
DATA_A=$(${DATA[3]}|iconv -f "windows-1251" -t "UTF-8")
DATA_B=$(${DATA[5]}|iconv -f "windows-1251" -t "UTF-8")
echo "sometext1 ${DATA[1]} \
sometext2 ${DATA[2]} \
sometext3 $DATA_A \
sometext4 ${DATA[4]} \
sometext5 $DATA_B"
我没有获得部分行文字的转换。
如果我只是转换这些变量,那么一切都很好:
echo ${DATA[3]}|iconv -f "windows-1251" -t "UTF-8"
echo ${DATA[5]}|iconv -f "windows-1251" -t "UTF-8"
答案 0 :(得分:2)
echo
DATA_A=$(echo "${DATA[3]}"|iconv -f "windows-1251" -t "UTF-8")
DATA_B=$(echo "${DATA[5]}"|iconv -f "windows-1251" -t "UTF-8")
或避免管道
DATA_A=$(iconv -f "windows-1251" -t "UTF-8" <<< "${DATA[3]}")
DATA_B=$(iconv -f "windows-1251" -t "UTF-8" <<< "${DATA[5]}")