我在 CentOS 中收到一条错误消息
'第 7 行:意外标记 'then' 附近的语法错误和'语法错误:文件意外结束'
这段代码的重点是向用户询问文件名,然后根据他们选择的内容复制移动或删除文件。
echo "Please enter the file name you wish to alter: "
read filename
if [ -f $filename ]; then
echo "Please enter either C, M, or D to copy, move or delete the file: "
read op
if [ "$op" = "C" ] || [ "$op" = "c" ]; then
echo "Please enter the destination directory in which you wish to copy to$
read dest
cp $filename $dest/$filename
echo "Complete"
elif [ "$op" = "M"] || [ "$op" = "m" ]; then
echo "Please enter the destination directory in which you wish to move to$
read dest
mv $filename $dest/$filename
echo "Complete"
elif [ "$op" = "D"] || [ "$op" = "d" ]; then
rm -i $filename
echo "Complete"
else "$filename does not exists try again."
fi
第三个echo
命令有一个未终止的字符串文字:
echo "Please enter the destination directory in which you wish to copy to$
也许你想写这个:
echo "Please enter the destination directory in which you wish to copy to:"
第五个echo
命令有同样的问题。
此外,此声明无效:
else "$filename does not exists try again."
也许你想写这个:
else
echo "$filename does not exists try again."
另外,没有fi
对应于第一个if
语句。
此外,语法[ "$op" = "M"]
无效。字符前必须有一个空格]
,例如:[ "$op" = "M" ]
.
你又遇到了同样的问题[ "$op" = "D"]
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句