Last Updated: March 02, 2016
·
793
· angelathewebdev

Command Line Execution

You might need to execute several commands on the Command Line Interface, or CLI for short.

Sometimes, you need to execute them in order, sometimes in parallel. This is done using different symbols and this post is a reference on how to do it.

Executed In Order

echo $HOME && pwd

Runs pwd if echo is successful.

echo $HOME || pwd

Runs pwd if echo failed

echo $HOME; pwd

Runs pwd after completing echo, regardless of its exit status.

Reference link: http://linux.die.net/Linux-CLI/x2622.htm

Executed In Parallel

echo $HOME & pwd

be careful with the placement of & operator. If it's used as the last character, then the entire command now runs in the background.

The above command runs both tasks with notification from the command line.

[1] 21736
/
/Users/angelawang
[1]+  Done                    echo $HOME
  • Note that commands are not executed in the order they were specified.

Multiple Execution

You can group command executions using parentheses like so

echo $HOME & (cd / && pwd)

and the output would look like this

[1] 21750
/Users/angelawang
/
[1]+  Done                    echo $HOME

2 Responses
Add your response

Great !!! :)

over 1 year ago ·

Thanks! This tip was quite helpful.

over 1 year ago ·