Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15447
| Path | csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Adam Danischewski <adam.danischewski@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | ARGV[@] Not Always Populated |
| Date | Tue, 1 Oct 2019 18:33:39 -0400 |
| Lines | 83 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.699.1569969240.2651.bug-bash@gnu.org> (permalink) |
| References | <CAOQZJ0GjaAvOO6VMppz=QHszASUxs0jfTFi+OHmLPEK50e+U1Q@mail.gmail.com> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | usenet.stanford.edu 1569969240 1228 209.51.188.17 (1 Oct 2019 22:34:00 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=2LNYM3CfRy7/sF7yIPu/WhrhkjGqYrb5p+zMxnnZZqU=; b=kEc8BzvoxZETweDdGD6Ime/pLLvW+y9LoDM4hMvSQxXY4paH4ZO+bC9VpTRMb0NQSB 61eqeCKDXVNi9shTBnRwCXpHkf2BlTuPYYhlH8GYfsV9rV6rVCd5mJv0dOM+VIaVZS8V 9otfUSsTZWwLhHGvqLn8n5x3HGvK9gGI90wNrLmpA0/l7zJCkuClgNBA2A7jsGWqzeTZ TSqgl4VtxBF2GbGt2c7gqyf+Wbljl97GhMU0gsKqfn5iyUWYZWlk66IFpo+3gVYCmU6C FLnF8LhXUJQvWUGuONb0HlW/2zqZoGFN3mNK4bqjKoOiGVJtPszuFgZTvGCrI/Ej5nOD iBng== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=2LNYM3CfRy7/sF7yIPu/WhrhkjGqYrb5p+zMxnnZZqU=; b=nKTrlHqiul6ps3+y0SKgjCpUmJqcDi3Jn6TqEum1E9hRrp13bqND/9bupocAueMKYD amG4w6/4a5eieT7FFZC412efkdISQAgOTk1iYLc9rVNO8jIdI7GQHfx1ziFmnb5gnRrx fZ0xieGVZ8qqPOFWNahL/Ih09vyks4UEnlC+5vqTtHKf6/eB3Q8FoZlMZ/oW6RfndRcC +DzFCQCnE/RA8MFkn9DTCVFmyGzLtyhcUsHG8vUPK7eQxleyv66IZnSHzmpC6TTFg2Md /WRZd3A6vYd3GjFWcOHLTHtdEk41nexz8zoPC511sbEJFGMNUgjfYGO1X54AyW+d9AkK O5DQ== |
| X-Gm-Message-State | APjAAAXtT9CloN9GHUNHhrj0gPH0ACrqhuI2qfas+uDgATiM/mIDCrus /YtylJzJ1hpFRJ1GIoX2wmTDulY5T9nEPMCM+GpA4iKj |
| X-Google-Smtp-Source | APXvYqwji8JtoAA7DIiLBwnCxfq1UQ1uVFQebHrhH1Hv7iyLS1L6GEkynvp8SapzN3l2ijazUl3dSznUUqbUAHHmvDY= |
| X-Received | by 2002:a2e:2416:: with SMTP id k22mr142979ljk.216.1569969230450; Tue, 01 Oct 2019 15:33:50 -0700 (PDT) |
| X-detected-operating-system | by eggs.gnu.org: Genre and OS details not recognized. |
| X-Received-From | 2a00:1450:4864:20::22c |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.23 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAOQZJ0GjaAvOO6VMppz=QHszASUxs0jfTFi+OHmLPEK50e+U1Q@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:15447 |
Show key headers only | View raw
*Configuration Information [Automatically generated, do not
change]:Machine: x86_64OS: linux-gnuCompiler: gccCompilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-LQgi2O/bash-5.0=. -f$uname output: Linux
amdubuntu 5.0.0-29-generic #31-Ubuntu SMP Thu Sep 12 13:05$Machine Type:
x86_64-pc-linux-gnuBash Version: 5.0Patch Level: 3Release Status: release*
A description of the bug behaviour.
If you don't access the ARGV array before you drop into a function, ARGV is
not populated.
E.g. If the script below is named test.bsh
If I run:
$> test.bsh arg1 arg1val arg2 arg2val arg3 arg3val
*I expect the following output: *
inside the options handler with i = 5, BASH_ARGV[5] is arg1, BASH_ARGV[] is
arg3val
inside the options handler with i = 4, BASH_ARGV[4] is arg1val, BASH_ARGV[]
is arg3val
inside the options handler with i = 3, BASH_ARGV[3] is arg2, BASH_ARGV[] is
arg3val
inside the options handler with i = 2, BASH_ARGV[2] is arg2val, BASH_ARGV[]
is arg3val
inside the options handler with i = 1, BASH_ARGV[1] is arg3, BASH_ARGV[] is
arg3val
inside the options handler with i = 0, BASH_ARGV[0] is arg3val, BASH_ARGV[]
is arg3val
Instead nothing is printed.
If you uncomment the echo at the top of the script then the printing is as
expected.
I realize the Bash Documentation states:
BASH_ARGV
An array variable containing all of the parameters in the
current bash
execution call stack. The final parameter of the last
subroutine call
is at the top of the stack; the first parameter of the
initial call is
at the bottom. When a subroutine is executed, the parameters
supplied
are pushed onto BASH_ARGV. The shell sets BASH_ARGV only
when in ex‐
tended debugging mode (see the description of the extdebug
option to
the shopt builtin below). Setting extdebug after the shell
has started
to execute a script, or
*referencing this variable when extdebug is not set, may
result in inconsistent values.*
Many people are using BASH_ARGV:
e.g.
https://stackoverflow.com/questions/2740906/how-to-access-command-line-arguments-of-the-caller-inside-a-function
If it's not too much trouble I think a lot of people would be glad if you
could make this work in a standardized way.
A short script or ‘recipe’ which exercises the bug and may be used to
reproduce it.
> #!/bin/bash
> ## If you uncomment the next line, command line args are printed;
> #echo "inside top version_ctl, args:${BASH_ARGV[@]}, #
> args:${#BASH_ARGV[@]} "
> function process_options() {
> local -i i=0
> local CURVAL=""
> local NEXTVAL=""
> for((i=$((${#BASH_ARGV[@]}-1));i>=0;i--)); do
> CURVAL=${BASH_ARGV[${i}]}
> NEXTVAL=${BASH_ARGV[$((${i}-1))]}
> echo "inside the options handler with i = $i, BASH_ARGV[${i}] is
> ${BASH_ARGV[${i}]}, BASH_ARGV[${next_arg}] is ${BASH_ARGV[${next_arg}]} "
> done
> return ${RETURN_CODE}
> }
>
> process_options
> exit 0
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
ARGV[@] Not Always Populated Adam Danischewski <adam.danischewski@gmail.com> - 2019-10-01 18:33 -0400
csiph-web