# 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和所有。
答案 0 :(得分:1)
来自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