Linking commands

Following on from pipes, we also have the ability to link commands in other ways:

 

  • ;
    • command 1 ; command 2 ; command 3
    • Do command 1, followed by command 2, followed by command 3
  • &
    • command &
    • Do command in a background subshell
    • Current shell does not wait for the command to finish, thus allowing the user to continue in the current shell
    • Use the jobs command to which processes are running in the background
  • &&
    • command 1 && command 2
    • Do command 1 and then proceed to command 2, only if command 1 exited successfully i.e. zero exit status
    • akin to logical AND
  • ||
    • command 1 || command 2
    • Do command 1 and then proceed to command 2, only if command 1 failed i.e. non-zero exit status
    • akin to logical OR

 

Above should be very obvious.

 

We have also already seen the pseudo ternary function delivered using:

  • [  condition ] && command || command