# 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..."
The above test script goes to infinite loop but it works fine if I use /usr/bin/bash
.
How to make this script to make it working in #!/usr/xpg4/bin/sh
?
Please help I'm new to shell scripting and no idea about POSIX and all.
From www.shellcheck.net: In POSIX sh, read -p is undefined.
Replace
read -p "do you want to continue (Y/N) ?" yn
by
printf "%s" "do you want to continue (Y/N) ?"
read yn