在 solaris 中读入无限循环
read in solaris going to an infinite loop
# cat test.sh
#!/usr/xpg4/bin/sh
while true; do
read -p "do you want to continue (Y/N) ?" yn
case $yn in
[Yy]* ) echo " Yes ";
[Nn]* ) echo " No "; exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo "execution completed..."
上面的测试脚本进入了无限循环,但如果我使用 /usr/bin/bash
.
它工作正常
如何制作此脚本以使其在 #!/usr/xpg4/bin/sh
中运行?
请帮助我是 shell 脚本的新手,对 POSIX 和所有东西一无所知。
来自 www.shellcheck.net:In POSIX sh, read -p is undefined.
替换
read -p "do you want to continue (Y/N) ?" yn
来自
printf "%s" "do you want to continue (Y/N) ?"
read yn
# cat test.sh
#!/usr/xpg4/bin/sh
while true; do
read -p "do you want to continue (Y/N) ?" yn
case $yn in
[Yy]* ) echo " Yes ";
[Nn]* ) echo " No "; exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo "execution completed..."
上面的测试脚本进入了无限循环,但如果我使用 /usr/bin/bash
.
如何制作此脚本以使其在 #!/usr/xpg4/bin/sh
中运行?
请帮助我是 shell 脚本的新手,对 POSIX 和所有东西一无所知。
来自 www.shellcheck.net:In POSIX sh, read -p is undefined.
替换
read -p "do you want to continue (Y/N) ?" yn
来自
printf "%s" "do you want to continue (Y/N) ?"
read yn