1
我有一个shell脚本是这样的:壳牌:如何处理包含文件名` N`或``在shell脚本
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Use: "$0" <file_name>"
echo "Convert files from GBK to UTF8"
exit
fi
for i in $*
# Generate temp file to avoid Bus error
iconv -f GBK -t utf-8 "$i" -o "$i.tmp"
mv "$i.tmp" "$i"
done
问题是$i
5月包含\n
,或其他有线字符,这使脚本无法执行(即使我已经用“”包装了它)。有什么办法可以忽略这些角色吗?
谢谢!但无论如何要处理包含'\ n'或其他有线字符的文件名? – MrROY
@MrROY:试试吧。我想你会发现它的工作原理。 –
是的,迭代“$ @”可以正确处理所有名称。 – choroba