Run multiple commands in linux/bash
#############################

a few methods:
==============

NOTE: the # hash sign below means run the command

run command2 if command1 is successful (exit status 0)

run command2 if command1 fails (exit status not 0)

run command2 if command1 is successful, then run command3 if command2 is successful

run command2 if command1 is successful, then run command3 if command2 fails

run command1 and then command2 and then command3, if either command fails, the next command still runs

run command1 into the background, then command2 into the background, then command3 into the background

see the commands status:

NOTE: you cant do: watch jobs -l  but you can do while true; do jobs -l; sleep 2; done; why does a while loop work and watch doesnt? because watch launches a subprocess of jobs -l , and jobs -l can only see within its same parent id. The parent id of each running job is that of the bash, and same of the jobs -l  that runs in the while loop, so they see each other and jobs -l will see those jobs. Its the same reason jobs -l  will not see other users backgrounded jobs, and other shells backgrounded processes even if its the same user. So in a while loop jobs -l  and the backgrounded proccesses have the same parent id (the parent being bash). On the other hand jobs -l  within a watch command, has the parent of that watch command, while the backgrounded processes are that of bash, so even though they are cousins/uncles/aunts, they still cant see.

http://stackoverflow.com/questions/2500436/how-does-cat-eof-work-in-bash

Printing multiline output to a file:
=====================================

NOTE: the # hash sign below actually means that it will be a comment

Then look at output, notice that bash will execute all of its substitutions, and if you dont want it then escape the cahracter that will cause substitution.

NOTE: the # hash sign below means run the command

Passing multiline output to a pipe:

Will output:

The if way:

command1 thru 4 will run, you can put a script in command1 thru 4 and it will run that script as if your running a bash script.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *