bug-bash
[Top][All Lists]
Advanced

[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: address@hidden,address@hidden
Subject: The set -o built-ins clobber the local argument variable address@hidden

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 address@hidden

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 address@hidden

Repeat-By:

Given the script demo-01.sh:

#!/bin/bash
builtin echo "Before set -o, address@hidden" $@
set -o ignoreeof on
builtin echo "After set -o,  address@hidden" $@
#EOF

We see that
        ./demo-01.sh one two three testing
prints
        Before set -o, address@hidden two three testing
        After set -o, address@hidden

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 address@hidden" $@
        set -o ignoreeof on
        builtin echo "In test_fnargs(), After  set -o address@hidden" $@
        return 0
}
# Test if it's the local $@ or the script $@ that gets clobbered
#
builtin echo "Before function call, address@hidden", $@
test_fnargs arguments to function only...
builtin echo "After function call,  address@hidden", $@
#
#
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 address@hidden" $@
        set -o ignoreeof on
        builtin echo "In test_fnargs(), After  set -o address@hidden" $@
        return 0
}
# Test if it's the local $@ or the script $@ that gets clobbered
#
builtin echo "Before function call, address@hidden", $@
test_fnargs arguments to function only...
builtin echo "After function call,  address@hidden", $@
#
#
builtin echo "Test arguments to script via function $@"
test_fnargs $@
builtin echo "After test_fnargs address@hidden address@hidden" $@
#EOF

For the call to the script

        $ ./test-02.sh one two three four testing

The output is as follows

        Before function call, address@hidden, one two three four testing
        In test_fnargs(), Before set -o address@hidden arguments to function 
only...
        In test_fnargs(), After  set -o address@hidden on
        After function call,  address@hidden, one two three four testing
        Test arguments to script via function one two three four testing
        In test_fnargs(), Before set -o address@hidden one two three four 
testing
        In test_fnargs(), After  set -o address@hidden on
        After test_fnargs address@hidden address@hidden 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







reply via email to

[Prev in Thread] Current Thread [Next in Thread]