[ Level 2 ] Get last argument in bash.

You could use the following methods to get the last argument that you pass to script.
#!/bin/bash
getLastArg1() {
  for last
  do
    true
  done
  echo $last
}

getLastArg2() {
  echo $@ | awk '{print($NF)}'
}

getLastArg3() {
  eval echo `echo \\$${#@}`
}

getLastArg1 $@
getLastArg2 $@
getLastArg3 $@
$ ./test.sh a b c
c
c
c
$

Wish this helps.

regards,
Stanley Huang

Comments

Popular posts from this blog

[Level 1] Rar tool for Solaris.

[Level 2] iif in Python