[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Subject: The set -o built-ins clobber the local argument variable $@
From: |
jamest |
Subject: |
Subject: The set -o built-ins clobber the local argument variable $@ |
Date: |
Sun, 10 Feb 2008 11:45:01 +0000 |
User-agent: |
Demon-WebMail/2.0 |
From: jamest
To: bug-bash@gnu.org,bash@packages.debian.org
Subject: The set -o built-ins clobber the local argument variable $@.
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 $@.
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 $@.
Repeat-By:
Given the script demo-01.sh:
#!/bin/bash
builtin echo "Before set -o, \$@=" $@
set -o ignoreeof on
builtin echo "After set -o, \$@=" $@
#EOF
We see that
./demo-01.sh one two three testing
prints
Before set -o, $@=one two three testing
After set -o, $@=on
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 \$@=" $@
set -o ignoreeof on
builtin echo "In test_fnargs(), After set -o \$@=" $@
return 0
}
# Test if it's the local $@ or the script $@ that gets clobbered
#
builtin echo "Before function call, \$@=", $@
test_fnargs arguments to function only...
builtin echo "After function call, \$@=", $@
#
#
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 \$@=" $@
set -o ignoreeof on
builtin echo "In test_fnargs(), After set -o \$@=" $@
return 0
}
# Test if it's the local $@ or the script $@ that gets clobbered
#
builtin echo "Before function call, \$@=", $@
test_fnargs arguments to function only...
builtin echo "After function call, \$@=", $@
#
#
builtin echo "Test arguments to script via function $@"
test_fnargs $@
builtin echo "After test_fnargs \$@... \$@=" $@
#EOF
For the call to the script
$ ./test-02.sh one two three four testing
The output is as follows
Before function call, $@=, one two three four testing
In test_fnargs(), Before set -o $@= arguments to function only...
In test_fnargs(), After set -o $@= on
After function call, $@=, one two three four testing
Test arguments to script via function one two three four testing
In test_fnargs(), Before set -o $@= one two three four testing
In test_fnargs(), After set -o $@= on
After test_fnargs $@... $@= 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
- Subject: The set -o built-ins clobber the local argument variable $@,
jamest <=