阅读solaris进入无限循环

时间:2016-03-09 20:04:04

标签: shell sh solaris solaris-10

# 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和所有。

1 个答案:

答案 0 :(得分:1)

来自www.shellcheck.netIn 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