parent trap EXIT appears to subshell but is not used

2021-03-29 Thread Valentin Lab

Hi,

I have encountered an issue when running some bash code from 4.3 that 
behave in an unexpected way on 4.4 or 5 ... I've managed to pinpoint the 
exact issue on my end.


Here is the code:


## 
trap -- 'echo bar' EXIT
(
  echo -n 'Subshell TRAP EXIT: '
  trap -p EXIT
  echo
)
echo main shell

##


Runnning this will give the same output on bash 4.4 and 5:

##  BEGIN OUTPUT
Subshell TRAP EXIT: trap -- 'echo bar' EXIT

main shell
bar
##  END OUTPUT


But will give this output on bash 4.3:

##  BEGIN OUTPUT
Subshell TRAP EXIT:
main shell
bar
##  END OUTPUT


We notice 2 important point:
- Bash >4.3 trap's is displaying parent shell's EXIT trap, while
  4.3 is not displaying it.
- None of them will execute any trap at the end of the subshell.


In 4.3, this makes sense to me. EXIT trap is not available and not executed.

In >4.3, I don't understand: 'trap -p' is displaying a trap that is not
really enabled ?


Notice that we can set an EXIT trap in the subshell, and then all bash 
version will display AND execute the trap at the end of the subshell. 
Which seems totally okay to me.



Is this strange behavior about bash >4.3 being able to display EXIT 
trap, but won't use them is expected ? I'd be happy to know about the 
rationale behind this if this is expected.



Many thanks,

Valentin Lab


PS: note that I found some other 'report' of that behavior here: 
https://unix.stackexchange.com/questions/282722#answer-374269




process substitution bug or difference from bash 4.4

2020-03-25 Thread Valentin Lab

Hi,

I have encountered an issue when running some bash code from 4.4 on a 
bash 5 ... I've managed to pinpoint the exact issue on my end.


Here are 2 functions that are quite similar, except the usage of "{ ; }" 
around the "cat":


## 
ouch() {
cat < <(echo bar)
cat "$1"
}

ouch2() {
{ cat; } < <(echo bar)
cat "$1"
}
##


Runnning this will give the same output on bash 4.4 and 5:


$ ouch <(echo "foo")
foo
bar


And by replacing "ouch" by "ouch2", I have the same output in bash 4.4 .

But running it on bash 5 will fail:

$ ouch2 <(echo "foo")
bar
cat: /dev/fd/63: No such file or directory


Is that expected ? I'd be happy to know about the rationale behind this 
(and the change) if this is expected.


Many thanks,

Valentin Lab