How Linux executes multiple commands in succession

Source: Internet
Author: User

Multiple commands can be placed on a single line, and their execution depends on the delimiter used between the commands.

if each command is separated by a semicolon (;) is separated, the command executes continuously, such as :

Reference

[Email protected]:/proc> printf "%s/n" "This is executed"; printf "%s/n" "and so are This"
This is executed
And so are this



if each command is separated by a &&, then these commands will continue to execute, and if there is an error in the middle of the command, then the subsequent command is no longer executed, yes, then the execution is complete :

Reference

[Email protected]:/proc> date && printf "%s/n" "The date command was successful"
Friday, August 28, 2009 18:28:16 CST
The date command was successful


All commands are successfully executed.

Reference


[Email protected]:/proc> date && llk && printf "%s/n" "The date command was successful"
Friday, August 28, 2009 18:28:52 CST
Bash:llk:command not found


Subsequent successful execution prompt statements are not output because the LLK command is not recognized.

if each command is double vertical (| |) separators, if the command encounters a command that can be executed successfully, then the command stops executing, and all subsequent commands will not be executed, even after the correct command is followed. If the command fails at the beginning, it executes | | After the next command, until it encounters a command that can execute successfully, and if all fails, all of these failed commands are tried once :

Reference

[Email protected]:/proc> date | | LS/| | Date ' duck! ' | | Uname-a
Friday, August 28, 2009 18:33:18 CST


The first command executes successfully! All subsequent commands are no longer executed.

Reference

[Email protected]:/proc> date ' duck! ' | | DAKKK | | Uname-a
Date: Invalid Day "duck!"
Bash:dakkk:command not found
Linux linux-beyes 2.6.27.29-0.1-pae #1 SMP 2009-08-15 17:53:59 +0200 i686 i686 i386 gnu/linux


The previous two commands failed until the last command to execute successfully was found.


How Linux executes multiple commands in succession

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.