Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
1. I'm pretty sure you need a space on each side of '=='
2. as you're not using the 'exit' to rtn a specific final status, just remove it. The script will exit/complete anyway.
The problem occurs though if I put the statement elsewhere though....
Code:
if [ $force!=yes ]; then
while ( [ $choice!=yes ] || [ $choice!=no ] ) do
echo -n "Are you sure you want to continue? (yes/no) "
read choice
echo
case "$choice" in
yes)
break;
;;
no)
exit;
;;
esac
done
fi;
Here, if i enter 'no' when prompted, my ssh session will end. If i don't put it in then my script will loop until i enter 'yes'.
If the script is executed, the break will exit the while loop (and continue with the rest of the script), if the exit clause is executed the script is ended and the prompt returns.
If the script is parsed (!!!!) the exit (any exit) will terminate your shell.
If you execute a script (./script.sh or just script.sh if it can be found in your PATH) the following will happen:
- A new (child) shell is opened,
- All the command in the script are executed in that (child) shell,
- When the script finishes the (child) shell is closed and control is returned to the (mother) shell.
If you parse a script all command in your script are executed in the (mother) shell, there is no (child) shell.
The exit command will close 'the' shell, depending on how you execute the script the child shell or the mother shell is closed. If, like you did, you parse the script, the moment an exit is encountered the mother shell is closed (the shell you type your commands).
For now: make your script executable (chmod 750 script.sh) and execute it (./script.sh).
Don't use 'exit' unless you want to force the exit value for a reason. In *nix shells & programs generally, the convention is a termination code of 0 (zero) means ok, anything else indicates an error.
By default, if you don't explicitly use eg 'exit 0', then the termination value is that of the last cmd run.
Hence the reason you often see code like
Code:
do_someprog
if [[ $? -ne 0 ]]
then
echo "error program failed"
exit 1
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.