Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

last parameter problem 1

Status
Not open for further replies.

ChesterPinkledink

Technical User
Mar 19, 2002
1
US
I am trying to call a filename in a script I wrote. The script has multiple cases and the number changes too frequently to put a constant number in. Is there a way I can call the last parameter and put it as the infile for a wc or a tr for example because it will always be the last parameter. Thanks
 

Hi,
it depends on your scripting language.

CSH

set filename = $argv[$#argv]

---

$#argv is the number of parameters -- x
$argv[x] will be the last paramter.

------------------------

SH/KSH


a="\$$#"
filename=`eval echo $a`

---------

$# is the number of parameters -- x
a="\$$#" will set a to $x
eval echo $a will then become
eval echo $x

which will then return parameter x.



 
That's it, i knew it was something like that, but you made my whole life much easier, helped me with a load of problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top