In Linux shell, & | a return value is returned when shell executes a command. The return value is saved in the shell variable $?. When $? = 0 indicates that the execution is successful. When $? = 1 indicates execution failed. Www.2cto.com sometimes, the next command depends on whether the previous command is successfully executed. For example, execute another command after a command is successfully executed, or execute another command after a command fails to be executed. Shell provides the & and | to implement command execution control. shell controls the execution of subsequent commands Based on the returned values of & or |. & (Command execution control) syntax format: command1 & command2 [& command3...] 1 Use & connect between commands to implement logic and functions. 2. Only the & left command returns true (the return value of the command is $? = 0), & the command on the right will be executed. 3. If a command returns false (the command returns $? = 1), the subsequent commands will not be executed. Example 1 malihou @ ubuntu :~ $ Cp ~ /Desktop/1.txt ~ /1.txt & rm ~ The commands in/Desktop/1.txt & echo "success" Example 1 start from ~ /Copy the 1.txt file in the Desktop directory ~ Directory. After the execution is successful, use rm to delete the source file. If the deletion is successful, a prompt is displayed. | (Command execution control) syntax format: command1 | command2 [| command3...] 1 use | connection between commands to implement logic or functions. 2 only | the command on the left returns false (command return value $? = 1), | the command on the right is executed. This is the same as the logic or syntax in c, that is, short-circuit logic or operations. 3. As long as a command returns true (the return value of the command is $? = 0), the subsequent commands will not be executed. Example 2 malihou @ ubuntu :~ $ Rm ~ /Desktop/1.txt | echo "fail" in example 2, if ~ /The file 1.txtdoes not exist in the Desktop directory. A prompt is displayed. Example 3 malihou @ ubuntu :~ $ Rm ~ /Desktop/1.txt & echo "success" | echo "fail" in Example 3, if ~ The file 1.txtexists in the/Desktop directory. The success prompt is displayed; otherwise, the fail prompt is displayed. Shell provides two methods () and {}) to execute several commands together, instead of independent execution. This method does not control whether or not the Command needs to be executed. It only combines multiple separate commands for execution. The return value of the final command is determined by the return value of the last command. () (Command combination) syntax format: www.2cto.com (command1; command2 [; command3. ..]) 1 A Command needs to exclusive one physical line. If multiple commands need to be placed in the same line, the commands are separated by the command separator. The execution effect is equivalent to that of multiple independent commands. 2 () indicates that multiple commands are executed as a whole in the current shell. Note that the commands enclosed by () are not switched to the current working directory before execution, that is, the command combinations are all executed under the current working directory, although the command contains the command to switch the directory. 3. Command combinations are often used in conjunction with command execution control. Example 4 malihou @ ubuntu :~ $ Rm ~ /Desktop/1.txt | (cd ~ /Desktop/; ls-a; echo "fail") in example 4, if the directory ~ /If the file 1.txtdoes not exist in the Desktop, run the command combination.