Skip to main content
deleted 3 characters in body
Source Link
JigglyNaga
  • 8.1k
  • 1
  • 28
  • 48

This is due to a bug in bash. During the Command Substitution step in

echo $( made up name ) 

made runs (or fails to be found) in a subshell, but the subshell is "optimized" in such a way that it doesn't use some traps from the parent shell. This was fixed in version 4.4.5:

Under certain circumstances, a simple command is optimized to eliminate a fork, resulting in an EXIT trap not being executed.

With bash 4.4.5 or higher, you should see the following output:

error.sh: line 13: made: command not found err status: 127 ! should not be reached ! 

The trap handler has been called as expected, then the subshell exits. (setoptset -e only causes the subshell to exit, not the parent, so that "should not be reached" message should, in fact, be reached.)

A workaround for older versions is to force the creation of a full, non-optimized subshell:

echo $( ( made up name ) ) 

The extra spaces are required to distinguish from Arithmetic Expansion.

This is due to a bug in bash. During the Command Substitution step in

echo $( made up name ) 

made runs (or fails to be found) in a subshell, but the subshell is "optimized" in such a way that it doesn't use some traps from the parent shell. This was fixed in version 4.4.5:

Under certain circumstances, a simple command is optimized to eliminate a fork, resulting in an EXIT trap not being executed.

With bash 4.4.5 or higher, you should see the following output:

error.sh: line 13: made: command not found err status: 127 ! should not be reached ! 

The trap handler has been called as expected, then the subshell exits. (setopt -e only causes the subshell to exit, not the parent, so that "should not be reached" message should, in fact, be reached.)

A workaround for older versions is to force the creation of a full, non-optimized subshell:

echo $( ( made up name ) ) 

The extra spaces are required to distinguish from Arithmetic Expansion.

This is due to a bug in bash. During the Command Substitution step in

echo $( made up name ) 

made runs (or fails to be found) in a subshell, but the subshell is "optimized" in such a way that it doesn't use some traps from the parent shell. This was fixed in version 4.4.5:

Under certain circumstances, a simple command is optimized to eliminate a fork, resulting in an EXIT trap not being executed.

With bash 4.4.5 or higher, you should see the following output:

error.sh: line 13: made: command not found err status: 127 ! should not be reached ! 

The trap handler has been called as expected, then the subshell exits. (set -e only causes the subshell to exit, not the parent, so that "should not be reached" message should, in fact, be reached.)

A workaround for older versions is to force the creation of a full, non-optimized subshell:

echo $( ( made up name ) ) 

The extra spaces are required to distinguish from Arithmetic Expansion.

Source Link
JigglyNaga
  • 8.1k
  • 1
  • 28
  • 48

This is due to a bug in bash. During the Command Substitution step in

echo $( made up name ) 

made runs (or fails to be found) in a subshell, but the subshell is "optimized" in such a way that it doesn't use some traps from the parent shell. This was fixed in version 4.4.5:

Under certain circumstances, a simple command is optimized to eliminate a fork, resulting in an EXIT trap not being executed.

With bash 4.4.5 or higher, you should see the following output:

error.sh: line 13: made: command not found err status: 127 ! should not be reached ! 

The trap handler has been called as expected, then the subshell exits. (setopt -e only causes the subshell to exit, not the parent, so that "should not be reached" message should, in fact, be reached.)

A workaround for older versions is to force the creation of a full, non-optimized subshell:

echo $( ( made up name ) ) 

The extra spaces are required to distinguish from Arithmetic Expansion.