Timeline for Getting the last argument passed to a shell script
Current License: CC BY-SA 2.5
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 7, 2023 at 18:51 | comment | added | Adam Katz |
@roamer – This only works in bash (/bin/bash ). You ran it through POSIX sh (/bin/sh ), which on many systems is not bash.
|
|
May 17, 2021 at 11:16 | comment | added | roamer |
Attention, ${!#} get nothing when execute script with sh XXX.sh 1 2 3
|
|
Sep 24, 2018 at 20:13 | comment | added | Steven Lu |
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.
|
|
Sep 20, 2018 at 21:55 | comment | added | user8017719 | The BASH_ARGV has the arguments when bash was called (or to a function) not the present list of positional arguments. | |
Dec 28, 2014 at 15:46 | comment | added | Big McLargeHuge |
$BASH_ARGV doesn't work inside a bash function (unless I'm doing something wrong).
|
|
Mar 13, 2010 at 19:47 | history | answered | Kevin Little | CC BY-SA 2.5 |