Quote:
echo ${15} It will work. Also $_ will give you the last argument of previous command. $ cat doit #!/bin/bash echo ${20} $ ./doit a b c d e f g h i j k l m n o p q r s t u v w x y z;echo "$_" t z |
#!/bin/bash
num="$#" lastp=( echo $@ ) echo ${lastp[$num]} |
Hi, /bin/bash.
Yes, ${15} worked on all the Bourne-related shells I found on (Debian) Linux: pdksh, dash, bash, bash-posix, zsh. It failed on sh/jsh on Solaris, but at least an error message was produced there. I changed my demo script to include this illustration for future use. Thanks ... cheers, makyo |
Hi, ygloo.
Yes, that seemed to have worked even in my v2 bash. Inventive ... cheers, makyo |
I just noticed nobody mentioned ${!#}. Guess what ${!#} is? Yep, it's the last command line argument.
$cat doit #!/bin/bash echo "No. of command line arguments = $#" echo "Last command line argument = ${!#}" $./doit 1 2 3 4 last No. of command line arguments = 5 Last command line argument = last |
Everyone seems to be using bash. I use zsh, in which parameters can be subscripted like python/etc.
i.e. the last argument is $argv[-1], or $@[-1], or $*[-1]. |
All times are GMT -5. The time now is 01:04 PM. |