Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-18-2007, 12:01 AM   #1
LQ Newbie
Registered: Dec 2006
Posts: 5

Rep: Reputation: 0
bash scripting : printing variable with the number within $i

I got this problem :
I want to print variable $1 to $n but for is not good enough in its current way, atleast how I use it :

for i in $(seq -w 1 9); do echo $$i; done
$i should give a number, but $$ is being done before so it's not good. I want it firstly to check what $i is and then do $ on the $i, if i=1 then $ $i = $1

How can I solve that?

Old 01-18-2007, 01:27 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Use indirection.
for ((n=1;n<5;n++)); do
echo "${!n}"
./ 12 43 56 78 90

Shift is usually used to handle one argument at a time.

Last edited by jschiwal; 01-18-2007 at 01:50 AM.
Old 01-18-2007, 01:30 AM   #3
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
I find this is nice and easy:

for arg in "$@"; do
    echo "we have an arg: $arg"
Use "$@" instead of $* to prevent problems with args which have whitespace in them.


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 Scripting - printing select lines in a file bullfrog1870 Linux - Newbie 16 11-08-2006 09:33 AM
Bash scripting: how can I reference a variable? frankie_DJ Programming 4 10-06-2006 05:13 AM
Scripting: accessing a variable stored in a variable? tomolesonjr Linux - Newbie 5 05-05-2006 08:47 PM
C programming: Variable number of parameters to function kenneho Programming 8 03-21-2006 06:21 AM
shell scripting: variable problem XST1 Programming 7 01-30-2005 01:45 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:55 AM.

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