LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-05-2006, 05:13 PM   #16
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46

Quote:
echo
echo " Show that simple dereferencing does not work above 9."
echo $4
echo $15
If you change that to:
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
 
Old 10-05-2006, 06:05 PM   #17
ygloo
Member
 
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
#!/bin/bash

num="$#"
lastp=( echo $@ )

echo ${lastp[$num]}
 
Old 10-05-2006, 06:25 PM   #18
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 719

Rep: Reputation: 72
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
 
Old 10-05-2006, 06:31 PM   #19
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 719

Rep: Reputation: 72
Hi, ygloo.

Yes, that seemed to have worked even in my v2 bash. Inventive ... cheers, makyo
 
Old 10-30-2006, 10:46 AM   #20
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
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

Last edited by /bin/bash; 10-30-2006 at 10:47 AM.
 
Old 10-30-2006, 11:20 AM   #21
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
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].
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script 'for each command line argument' true_atlantis Linux - Newbie 3 01-28-2009 02:51 PM
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 01:08 AM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 12:31 PM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 05:35 PM
Finding out my video card from the command line devinWhalen Linux - Hardware 3 04-15-2004 12:59 PM


All times are GMT -5. The time now is 07:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration