Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15452 > unrolled thread
| Started by | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| First post | 2019-10-02 09:10 -0400 |
| Last post | 2019-10-02 09:10 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: ARGV[@] Not Always Populated Chet Ramey <chet.ramey@case.edu> - 2019-10-02 09:10 -0400
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Date | 2019-10-02 09:10 -0400 |
| Subject | Re: ARGV[@] Not Always Populated |
| Message-ID | <mailman.754.1570021822.2651.bug-bash@gnu.org> |
On 10/1/19 6:33 PM, Adam Danischewski wrote: > If you don't access the ARGV array before you drop into a function, ARGV is > not populated. > [...] > 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.* By default, the array is lazily populated: if you reference BASH_ARGV, and it hasn't been set up, it will be initialized using the current positional parameters. > 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. Doesn't that suggest that the best way to use it in a `standardized' way is to run `shopt -s extdebug' at the script's top level, before trying to reference BASH_ARGV? -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Back to top | Article view | gnu.bash.bug
csiph-web