Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Shell - Run multipl...
 
Share:
Notifications
Clear all

[Solved] Shell - Run multiple command in one single line ...

1 Posts
1 Users
0 Likes
1,789 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
Topic starter  

In a Linux shell, Bash for example, one can concat multiple commands on a single line. For example (this example makes no practical sense, it's just to illustrate), let's say we'd like to list the files in the current directory (ls) and after that we'd like to see the task we have running (ps).

You can do this in two steps:

ls
ps

You can also combine them in one line:

ls ; ps

Which will first execute ls, and then ps, no matter if either of these commands failed.

You can however use the "result" of the first command to decide if we do or do not execute the second command. With "result" I mean if the first statement worked correctly or not.

ls || ps

In this case, ls will be tried first. If it fails, then ps will be used instead. Read it as  "ls OR ps" ...

You can also decide that the second command should only be run if the first command succeeded:

ls && ps

In this example ps will only execute when ls succeeded. Read this as "ls AND ps" ...


   
ReplyQuote
Share: