Only if you send me a script that makes my PC brew good beer and shoot it out the useless floppy drive into my mug ;D
Hi
I just want a shell script which gives me the last argument passed.
For example,
if the script script.sh is executed
>script.sh one two three
it must give me "three"
Also,
>script.sh one two "three four"
must give me "three four"
Could u geeks help me ??????
thanks in advance,
rameshvl
Only if you send me a script that makes my PC brew good beer and shoot it out the useless floppy drive into my mug ;D
[quote author=rameshvl link=board=9;threadid=6893;start=0#64253 date=1051249815]
Hi
I just want a shell script which gives me the last argument passed.
For example,
if the script script.sh is executed
>script.sh one two three
it must give me "three"
Also,
>script.sh one two "three four"
must give me "three four"
Could u geeks help me ??????
thanks in advance,
rameshvl
[/quote]
You know, if you are looking for help, you might want to be more courteous... Calling people "geeks" is kind of rude.
Did you even look or try anything?
Put this in a file and run it.
echo $3
$* is all arguments providedCode:#!/bin/bash ARGV=$* echo $ARGV |awk ' { printf(" \n %d and arg-1 %d ", $NF , $(NF-1) ); } '
there you go, NF is the number of records you can play with that.
bash scripting supports printf() - kewl, you learn something every day.
yep, oh forgot to say if you ain't to good at coding %d = interget(number), %s (string).
you can also have if statements within awk so it's farily straightforward.
[quote author=trickster link=board=9;threadid=6893;start=0#64269 date=1051273494]
You know, if you are looking for help, you might want to be more courteous... Calling people "geeks" is kind of rude.
[/quote]
He meant geeks as in computer geeks and most people here I bet will call themselves geeks all the time and dont mind being called geeks, it's a badge of honor![]()
exactly, thanks a lot, Mr. vlad902
Anyway, I found a simpler solution for my problem, let me share it with u all,
shift $(($# - 1))
will do the trick,
I can get the last argument with $1 after the above line
Thanks a lot to everyone who replied,
regards,
rameshvl
The simplest would be to use the special variable !$ which always contains the last argument to the last command
This tip was brought to you by www.unixtips.org![]()
Bookmarks