- How to pass yes or no in shell script?
- What is the purpose of the $? variable?
- What special variable is used to determine the exit status of a previously executed command?
How to pass yes or no in shell script?
In that case, we can simply wrap our yes/no prompt in a while loop. #!/bin/bash while true; do read -p "Do you want to proceed? (yes/no) " yn case $yn in yes ) echo ok, we will proceed; break;; no ) echo exiting...; exit;; * ) echo invalid response;; esac done echo doing stuff...
What is the purpose of the $? variable?
“$?” is a variable that holds the return value of the last executed command. “echo $?” displays 0 if the last command has been successfully executed and displays a non-zero value if some error has occurred. The bash sets “$?” To the exit status of the last executed process.
What special variable is used to determine the exit status of a previously executed command?
The $? variable represents the exit status of the previous command. Exit status is a numerical value returned by every command upon its completion.