Page 1 of 1

Shell – Run multiple command in one single line …

Shell – Run multiple command in one single line …

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.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.

RSS Feed

Home Forums Software Linux Software Shell – Run multiple command in one single line …

This topic contains 0 replies, has 1 voice, and was last updated by  hans 5 years, 2 months ago.

Viewing 1 post (of 1 total)
  • Author
  • 3704


    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:


    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” …

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.