linux:bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux:bash [2026/01/10 14:59] – [Control Operators] mhlinux:bash [2026/01/11 11:57] (current) – [Control Operators] mh
Line 122: Line 122:
  
 Try something, but if it errors (exit code ≠ 0):  Try something, but if it errors (exit code ≠ 0): 
-  * silence the error message (send to /dev/null)+  * silence the error message (send to ''/dev/null'')
   * immediately run ''true'' ( || operator passes along to second part)   * immediately run ''true'' ( || operator passes along to second part)
   * Overall ''exit'' status becomes success (exit code = 0)   * Overall ''exit'' status becomes success (exit code = 0)
Line 142: Line 142:
 It’s about acknowledging expected non-problems. It’s about acknowledging expected non-problems.
  
 +----
 +
 +=== && AND Operator ===
 +
 +This control operator tells bash to run a second command **only if the first command before it succeeded**.
 +
 +If the first command fails, the second command is entirely skipped.
 +
 +**Example**
 +<code bash>
 +$ rm hello.txt && echo "Deleted file."
 +rm: cannot remove 'hello.txt': No such file or directory
 +</code>
 +
 +Because the file did not exist, the ''echo'' command was not run.
 ===== Arguments ===== ===== Arguments =====
  
  • linux/bash.1768053556.txt.gz
  • Last modified: 2026/01/10 14:59
  • by mh