Control Operators in Linux

Control operators allow you to specify the conditions under which different commands should be executed, which can make your scripts more flexible and adaptable to different scenarios. They allow you to combine multiple commands into a single command line

several control operators

  1. ; (semicolon)

  2. & (ampersand)

  3. || (OR operator)

  4. && (AND operator)

  5. \ (backslash)

; (semicolon): This operator allows you to execute multiple commands in sequence, regardless of whether the previous command was successful or not

& (ampersand): This operator allows you to execute a command in the background, allowing you to continue using the terminal while the command is running.

notice sleep command is returning the process ids of the commands except last

|| (OR operator): This operator allows you to execute multiple commands in sequence, with the second command only being executed if the first command fails

it will only create an src directory if the src directory does not exist

&& (AND operator): This operator allows you to execute multiple commands in sequence, with the next command only being executed if the first command completes successfully

it will only create an App.js file in the src directory if the src directory exists

(\) backslash: backslash can be used to escape other special characters

This will execute the two commands as if they were written on a single line.

Another example

Did you find this article valuable?

Support Muhammad Usama by becoming a sponsor. Any amount is appreciated!