2016-03-09 66 views
0
# 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,它工作正常。閱讀solaris去無限循環

如何讓此腳本使它在#!/usr/xpg4/bin/sh中工作? 請大家幫忙我是shell腳本編程新手,對POSIX和其他所有人都不瞭解。

回答

1

www.shellcheck.netIn POSIX sh, read -p is undefined.

通過

printf "%s" "do you want to continue (Y/N) ?" 
read yn 
+0

甚至取代

read -p "do you want to continue (Y/N) ?" yn 

:'printf 「上?你是否要繼續?(Y/N)」' – jlliagre

+0

能否請你告訴我如何使用sed命令來替換一行,如果一些字符串匹配在該行? –

+0

@AlenPeter:'sed's /.* some string。*/new line /'file' – Cyrus