Very simple BASH scripting question
I have two commands, command1 and command2. In a script, I want to run command1, then once command1 is complete, I want to run command2. I can't remember what you put between commands to get the 2nd one to wait on the 1st to complete. I have tried the two that I thought it might be, "wait" and "&", with no luck
|
try &&
|
If you only want two to run if one was successful, do
what asb said; if you want it to run regardless of the outcome of command1, use a semicolon. command1; command2 as opposed to command1 && command2 Cheers, Tink |
Thanks. That worked. I knew it was something along those lines. I've been out of scripting for way too long.
|
Third way exists too, || can also be used in between the commands.
command1 || command2 in this case command2 gets executed if command1 fails. |
I actually needed &&, but I had never heard of || or ;. Those are good to know. I;m sure I'll run into situations where I need them. Thanks everyone.
|
It's really just basic boolen logic:
&& = and Thus command1 && command2 means that is command1 gets executed without failing (i.e. is "true"), then command2 must get executed too. || = or Thus either command1 OR command2 must be executed. Since command1 is tried first, command2 will get executed only if command1 fails (i.e. is "false"). It's the same thing as in bash if. |
All times are GMT -5. The time now is 11:04 AM. |