我正在尝试开发一个bash脚本,该脚本处理可能包含空间名称的文件列表。
(我已经用文件名中的空格咨询过脚本中的问题,以及为什么我不能在bash脚本中转义空格?但是似乎无法完善我的脚本。)
这是我的剧本。实际过程更加复杂,在此我将其简化为简单的file
命令。
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage is $0 <files to be tested>"
exit
fi
allfilestobetesed=$@
for filetobetested in "$allfilestobetested"
do
file "$filetobetested"
done
如何改善我的脚本?
allfilestobetested
如果可以,您应该摆脱变量:
for filetobetested in "$@"; do
file "$filetobetested"
done
将正确扩展
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句