Skip to main content
added 148 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function.

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.


For you updated question, you forget that the ERR trap will still be called if the command that returns the non-zero exit status is the last command in the AND or OR list.

From the bash manual, with my emphasis:

The ERR trap is not executed if the failed command is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted using !.

Your example is true && false, and since false is last in the AND list, it triggers the ERR trap.

Another way of saying this is that the ERR trap is called if the command that decides the exit status of a list or pipeline returns a non-zero exit status (or zero exit status if ! is used with that command).

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function.

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.


For you updated question, you forget that the ERR trap will still be called if the command that returns the non-zero exit status is the last command in the AND or OR list.

From the bash manual, with my emphasis:

The ERR trap is not executed if the failed command is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted using !.

Your example is true && false, and since false is last in the AND list, it triggers the ERR trap.

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function.

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.


For you updated question, you forget that the ERR trap will still be called if the command that returns the non-zero exit status is the last command in the AND or OR list.

From the bash manual, with my emphasis:

The ERR trap is not executed if the failed command is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted using !.

Your example is true && false, and since false is last in the AND list, it triggers the ERR trap.

Another way of saying this is that the ERR trap is called if the command that decides the exit status of a list or pipeline returns a non-zero exit status (or zero exit status if ! is used with that command).

added 148 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function.

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.


For you updated question, you forget that the ERR trap will still be called if the command that returns the non-zero exit status is the last command in the AND or OR list.

From the bash manual, with my emphasis:

The ERR trap is not executed if the failed command is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted using !.

Your example is true && false, and since false is last in the AND list, it triggers the ERR trap.

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function.

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function.

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.


For you updated question, you forget that the ERR trap will still be called if the command that returns the non-zero exit status is the last command in the AND or OR list.

From the bash manual, with my emphasis:

The ERR trap is not executed if the failed command is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted using !.

Your example is true && false, and since false is last in the AND list, it triggers the ERR trap.

deleted 96 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function (your line number is off by one, possibly due to some last-minute editing of the script source).

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this also sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function (your line number is off by one, possibly due to some last-minute editing of the script source).

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this also sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.

Your script is triggering the ERR trap due to the return status of the control_operators call, which is non-zero. The test in the function does not directly trigger the trap.

The trap output indicates this by the line number it prints, which will be the line with the call to the function.

The trap output also indicates where this non-zero exit status comes from, which is the result of the test in the function. Since the test is the last thing executed in the function, this sets the function's exit status.

The function call is not part of an AND or OR list, so the trap is triggered.

added 8 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading