[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Here document / redirection / background process weirdness
From: |
Martin Jackson |
Subject: |
Here document / redirection / background process weirdness |
Date: |
Tue, 5 Mar 2013 13:52:20 +0100 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu'
-DCONF_VENDOR='unknown'
-DLOCALEDIR='/home/mjackson/src/bash-4.2/_install/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib
-g -O2
uname output: Linux stagecoach 3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25
18:26:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu
Bash Version: 4.2
Patch Level: 0
Release Status: release
Description:
When executing a here document in bash, with the here document piped to
another instance of bash, where the here document contains "echo <&- &;
wait", the here document gets executed twice. I have seen this on Ubuntu
both with the current 4.2.37 from ubuntu and the latest bash tarball
(details above)
Repeat-By:
#!/home/mjackson/src/bash-4.2/_install/bin/bash
/home/mjackson/src/bash-4.2/_install/bin/bash <<EOF
declare -i a=0
echo BASHPID is \$BASHPID
true </dev/null & wait # NOP
let a++
echo a is \$a, BASHPID is \$BASHPID
EOF
Prints:
BASHPID is 30866
a is 1, BASHPID is 30866
a is 2, BASHPID is 30866
Fix:
Adding a manual 'exit' statement at the end of the here document seems
to be a workaround:
#!/home/mjackson/src/bash-4.2/_install/bin/bash
/home/mjackson/src/bash-4.2/_install/bin/bash <<EOF
declare -i a=0
echo BASHPID is \$BASHPID
true </dev/null & wait # NOP
let a++
echo a is \$a, BASHPID is \$BASHPID
exit
EOF
Prints:
BASHPID is 30895
a is 1, BASHPID is 30895
- Here document / redirection / background process weirdness,
Martin Jackson <=