shell脚本中的If-else开关大小写

p5fdfcr1  于 2023-02-13  发布在  Shell
关注(0)|答案(1)|浏览(150)
#!/bin/sh

echo Enter choice :
echo a : To create a file, name given by user.
echo b : To copy file to another location.
echo c : To determine minimum age to vote.

read choice
case $choice in

    a) echo Enter the name of file.
        read name
        mkdir $name ;;
    b) echo Enter file name you want to copy
        read  file_name
      echo Enter location where you want to copy $file_name
        read location
        cp -r  $file_name "$location";;
    c) echo Enter age :
        read age
        if [ age -ge 18 ]
        then 
        echo You are eligible 
        else 
        echo You are not eligible
        "fi" 
        ;;
        
    *) echo Please! Enter correct choice.
 
esac

在这一点上,我选择了选项c,但它显示了我无法解决的错误。
错误:

Enter choice :
a : To create a file, name given by user.
b : To copy file to another location.
c : To determine minimum age to vote.
c
./a.sh: 27: Syntax error: ";;" unexpected (expecting "fi")
rks48beu

rks48beu1#

帮助修复您的代码,您可以比较您的代码作为参考

#!/bin/sh

echo Enter choice :
echo a : To create a file, name given by user.
echo b : To copy file to another location.
echo c : To determine minimum age to vote.

read -r choice
case $choice in

    a) echo Enter the name of file.
        read -r name
        mkdir "$name" ;;
    b) echo Enter file name you want to copy
        read -r file_name
      echo Enter location where you want to copy "$file_name"
        read -r location
        cp -r  "$file_name"  "$location";;
    c) echo Enter age :
        read -r age
        if [ "$age" -ge 18 ]
        then 
        echo You are eligible 
        else 
        echo You are not eligible
        fi
        ;;
        
    *) echo Please! Enter correct choice.
 
esac

相关问题