Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    $BASH_ARGV doesn't work inside a bash function (unless I'm doing something wrong). Commented Dec 28, 2014 at 15:46
  • 1
    The BASH_ARGV has the arguments when bash was called (or to a function) not the present list of positional arguments.
    – user8017719
    Commented Sep 20, 2018 at 21:55
  • Note also what BASH_ARGV will yield you is the value that the last arg that was given was, instead of simply "the last value". For example!: if you provide one single argument, then you call shift, ${@:$#} will produce nothing (because you shifted out the one and only argument!), however, BASH_ARGV will still give you that (formerly) last argument.
    – Steven Lu
    Commented Sep 24, 2018 at 20:13
  • Attention, ${!#} get nothing when execute script with sh XXX.sh 1 2 3
    – roamer
    Commented May 17, 2021 at 11:16
  • @roamer – This only works in bash (/bin/bash). You ran it through POSIX sh (/bin/sh), which on many systems is not bash.
    – Adam Katz
    Commented Mar 7, 2023 at 18:51