有效的 Shell 脚本无法在 WSL 中运行

有效的 Shell 脚本无法在 WSL 中运行

我有一个简单的 shell 脚本,它在 VM 上运行完全正常,但在 WSL 中出现语法错误。

insert(){
    read -p "Enter Name: " name
    read -p "Enter Phone Number: " phoneNumber
    echo "$name $phoneNumber" >> data.txt

}
id=100
while [ True ]
do
echo -e "[1] Insert data.\n[2] Search.\n[3]Remove Data.\n[q] Quit."
read -p "Enter yout Choice: " choice
if [ $choice -eq "4" ]; then
    break

elif [ $choice -eq "1" ];then
    insert
elif [ $choice -eq "2" ];then

    echo "Search"
elif [ $choice -eq "3" ];then

    echo "Remove"
else

    echo "Please enter proper input."
fi
done

WSL 中的输出

Enter Name: Poojan
: bad variable nameme
Enter Phone Number: 23212
: bad variable nameoneNumber
: not found
: not found}
try.sh: 15: Syntax error: "elif" unexpected (expecting "then")

VM 中的输出

[1] Insert data.
[2] Search.
[3]Remove Data.
[q] Quit.
Enter yout Choice: 1
Enter Name: Poojan
Enter Phone Number: 3423423

相关内容