我正在尋找foo
可能包含以下內容的內容:
$ echo blah && foo && echo the sequel
blah
Do you want to continue? [y/n]: n
$ echo blah && foo && echo the sequel
blah
Do you want to continue? [y/n]: y
blah
$
答案1
標準?不。
你可以做
foo() {
local answer
while true; do
read -p "Do you wish to continue? [y/n]: " answer
case $answer in
[yY]*) return 0 ;;
[nN]*) return 1 ;;
esac
done
}