ojxoia
Last Updated: March 02, 2016
·
599
· angelathewebdev
03ba33ccbb0ef8b3849096c1fe8f48e6

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
Say Thanks
Respond

2 Responses
Add your response

19198
F5875741c303d13ed5c9277cbaa638b2

Great !!! :)

over 1 year ago ·
19306
Photo

Thanks! This tip was quite helpful.

over 1 year ago ·
Filed Under