Reputation: 4399
I have just noticed that exporting this converts it into an ordinary variable with no special meaning in subshells. Is this a security feature of bash?
Upvotes: 4
Views: 1224
Reputation: 6228
This is a snippet to check the feature:
#! /bin/bash
exec 3>| trace.txt
BASH_XTRACEFD=3
set -x
# Something to trace
i=1 ; test "$i" -gt 2
# Now in a subshell
(i=2 ; test "$i" -gt 2)
# Let's export it
export BASH_XTRACEFD
# Again check trace
i=3 ; test "$i" -gt 2
# Now in a subshell
(i=4 ; test "$i" -gt 2)
And here is trace.txt
:
+ i=1
+ test 1 -gt 2
+ i=2
+ test 2 -gt 2
+ export BASH_XTRACEFD
+ i=3
+ test 3 -gt 2
+ i=4
+ test 4 -gt 2
It works! May be we have different bash version. Mine is 4.3.11(1)-release (x86_64-pc-linux-gnu)
. What's yours?
Upvotes: 2