From: jamest To: bug-bash@gnu.org,[EMAIL PROTECTED] Subject: The set -o built-ins clobber the local argument variable [EMAIL PROTECTED]
Configuration Information [Automatically generated, do not change]: Machine: i486 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' \ -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc'\ -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H \ -I. -I../bash -I../bash/include -I../bash/lib -g -O2 -Wall uname output: Linux iotia2 2.6.22-14-generic #1 SMP Fri Feb 1 04:59:50 UTC 2008 i686 GNU/Linux Machine Type: i486-pc-linux-gnu Bash Version: 3.2 Patch Level: 25 Release Status: release Description: [Detailed description of the problem, suggestion, or complaint.] set -o option <parameter> causes <parameter> to be subsituted for all of the parameters in the current copy of [EMAIL PROTECTED] Repeat-By: Description: [Detailed description of the problem, suggestion, or complaint.] the built in command "set -o option <parameter>" causes "<parameter>" to be subsituted for all of the values in the current copy of [EMAIL PROTECTED] Repeat-By: Given the script demo-01.sh: #!/bin/bash builtin echo "Before set -o, [EMAIL PROTECTED]" $@ set -o ignoreeof on builtin echo "After set -o, [EMAIL PROTECTED]" $@ #EOF We see that ./demo-01.sh one two three testing prints Before set -o, [EMAIL PROTECTED] two three testing After set -o, [EMAIL PROTECTED] he script demo-02.sh shows the behaviour of an option in a function call. 1) It calls a test function with arguments set in the script 2) It calls the test function with the $@ variable available to the parent script. #!/bin/bash function test_fnargs() { builtin echo "In test_fnargs(), Before set -o [EMAIL PROTECTED]" $@ set -o ignoreeof on builtin echo "In test_fnargs(), After set -o [EMAIL PROTECTED]" $@ return 0 } # Test if it's the local $@ or the script $@ that gets clobbered # builtin echo "Before function call, [EMAIL PROTECTED]", $@ test_fnargs arguments to function only... builtin echo "After function call, [EMAIL PROTECTED]", $@ # # he script demo-02.sh shows the behaviour of an option in a function call. 1) It calls a test function with arguments set in the script 2) It calls the test function with the $@ variable available to the parent script. #!/bin/bash function test_fnargs() { builtin echo "In test_fnargs(), Before set -o [EMAIL PROTECTED]" $@ set -o ignoreeof on builtin echo "In test_fnargs(), After set -o [EMAIL PROTECTED]" $@ return 0 } # Test if it's the local $@ or the script $@ that gets clobbered # builtin echo "Before function call, [EMAIL PROTECTED]", $@ test_fnargs arguments to function only... builtin echo "After function call, [EMAIL PROTECTED]", $@ # # builtin echo "Test arguments to script via function $@" test_fnargs $@ builtin echo "After test_fnargs [EMAIL PROTECTED] [EMAIL PROTECTED]" $@ #EOF For the call to the script $ ./test-02.sh one two three four testing The output is as follows Before function call, [EMAIL PROTECTED], one two three four testing In test_fnargs(), Before set -o [EMAIL PROTECTED] arguments to function only... In test_fnargs(), After set -o [EMAIL PROTECTED] on After function call, [EMAIL PROTECTED], one two three four testing Test arguments to script via function one two three four testing In test_fnargs(), Before set -o [EMAIL PROTECTED] one two three four testing In test_fnargs(), After set -o [EMAIL PROTECTED] on After test_fnargs [EMAIL PROTECTED] [EMAIL PROTECTED] one two three four testing $ Note that the arguments passed into the function do not affect the arguments that were passed to the shell from the command line: these are preserved across the function call. Thank you very much for your attention. -- James Tullett