我是新手来堆叠溢出,所以请忍受格式化 这是一个真正的问题
我正在创建一个程序来复制,删除和移动文件,但仍无法解决错误的回声错误,我该怎么办? 我已经阅读了另一个相关的问题,其中包括一个;但这也没有解决问题
#!/bin/bash
echo "Menu "
echo "1. Copy a File "
echo "2. Remove a file "
echo "3. Move a file"
echo "4. Quit"
echo "Enter ur Choice \c"
read Choice
case " $Choice " in
1. echo "Enter File name to copy \c"
read f1
echo " Enter File name \c "
read f2
if [ -f $f1 ]
then
cp $f1 $f2
else
echo "$f1 does not exist"
fi
;;
2. echo "Enter the File to be removed "
read r1
if [ -f $r1 ]
then
rm -i $r1
else
echo "$r1 file does not exist "
fi
;;
3.
echo "Enter File name to move \c"
read f1
echo "Enter destination \c "
read f2
if [ -f $f1 ]
then
if [ -d $f2 ]
then
mv $f1 $f2
fi
else
echo "$f1 does not exist"
fi
;;
4.
echo "Exit......."
exit;;
esac
错误
./script13.sh: line 10: syntax error near unexpected token `echo'
./script13.sh: line 10: ` 1. echo "Enter File name to copy \c " '
root@Kalilinux1:~/bin#
答案 0 :(得分:0)
你缺少括号,所以:
#!/bin/bash
echo "Menu "
echo "1. Copy a File "
echo "2. Remove a file "
echo "3. Move a file"
echo "4. Quit"
read -p "Enter ur Choice >>> "
case " $Choice " in
1) echo "Enter File name to copy \c"
read f1
echo " Enter File name \c "
read f2
if [ -f $f1 ]
then
cp $f1 $f2
else
echo "$f1 does not exist"
fi
;;
2) echo "Enter the File to be removed "
read r1
if [ -f $r1 ]
then
rm -i $r1
else
echo "$r1 file does not exist "
fi
;;
3)
echo "Enter File name to move \c"
read f1
echo "Enter destination \c "
read f2
if [ -f $f1 ]
then
if [ -d $f2 ]
then
mv $f1 $f2
fi
else
echo "$f1 does not exist"
fi
;;
4)
echo "Exit......."
exit;;
esac
答案 1 :(得分:0)
而不是第10行中的1.
,您应该使用1)
。执行案例陈述的正确方法是:
case "$Choice" in
1) ...
;;
2) ...
;;
另外,删除" $Choice "
中的空格。