Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
The $#ARGV just returns the number of elements in the input array of arguements. Im sure theres a comparable shell function. "man bash" would probably be a good start.
I just want a shell script which gives me the last argument passed.
rameshvl, could you show us at least you made *some* effort trying to work it out yourself?
AND, I DID TRY before posting my problem, and I NEED NOT PROVE IT TO U.
No need to shout, and IMNSHO, you do.
Why? It means we don't need to think for instance about stuff like this being a school project (I personally loathe contributing to those unless ppl tell it up front and match the criteria below). Showing what you did and where it went wrong is also easier cuz we don't have to reinvent the whole wheel again. Plus it's what I hope to be part of minimal netiquette, courtesy, respect or whatever you'd call it amongst LQ members.
Say args=( $@ ), then if you have $# (or ${#args[@]} in this case), then if you don't want to show the 1st 2 args, why not do
for n in $(seq 2 ${#args[@]}); do printf "%s${args[$n]}\n"; done
Btw, due to $IFS in the interactive Bash shell squishing "three four" together won't work.
Well there is a way of getting around the $IFS seperator. You could use the shift to get to the last parmeter. And then just use $1 to extract it. Something like:
Thanks Mik, it worked !!! Can u suggest me some links where i can learn more abt these stuff ??
and Mr. unSpawn, i got pissed off for the WAY u had put it, not for anything else, I do understand ur intention, but u cud have been more polite (as being a moderator replying a poster atleast). thanx anyway.
and Mr. unSpawn, i got pissed off for the WAY u had put it, .*but u cud have been more polite.*thanx anyway.
LOL! And I thought subtly posting it as a question saying "could" instead of "must" should do the trick...
Well there is a way of getting around the $IFS seperator. You could use the shift to get to the last parmeter. And then just use $1 to extract it. Something like:
You are resurrecting an almost 6 years old thread! frenchn00b, if you want to print the last field of a line passed through a pipe, just use awk '{print $NF}'.
You are resurrecting an almost 6 years old thread!
And for that I'm thankful. Because I'm able to learn something new from reading it.
I'm still trying to understand "${!#}" though. I've been looking through the Advanced Bash Scripting Guide, but I haven't been able to find any specific reference explaining what it does exactly. Could someone explain it to me?
And for that I'm thankful. Because I'm able to learn something new from reading it.
I'm still trying to understand "${!#}" though. I've been looking through the Advanced Bash Scripting Guide, but I haven't been able to find any specific reference explaining what it does exactly. Could someone explain it to me?
Look in info bash under "Basic Shell features -> Shell Expansions -> Shell Parameter Expansion" or in the index under "!" for details.
I'm still trying to understand "${!#}" though. I've been looking through the Advanced Bash Scripting Guide, but I haven't been able to find any specific reference explaining what it does exactly. Could someone explain it to me?
To me it is simply the "new" notation for indirect referencing, introduced in Bash version 2:
Code:
${!variable}
instead of the classic \$$var notation. Assumed that $# is a special variable that gives the number of arguments, ${!#} is a reference to the last argument. Very similar to $NF in awk.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.