LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-07-2009, 05:38 PM   #1
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Rep: Reputation: 0
Storing over 10 variables


Hey guys,

I have a script that takes in user input from the terminal and stores it as variables:

For example:

Code:
if [ $# -lt 9 ]; then
    echo ""
    echo 1>&2 Usage: $0 ["bed file 1"] ["bed file 2"] ["bed file 3"] ["Window Size"] ["Gap Size"] ["E Value"] ["Species"] ["Known Genes File"] ["Promoter Extension"]
    echo ""
    exit 1
fi

BEDFILE1=$1
BEDFILE2=$2
BEDFILE3=$3
WINDOW_SIZE=$4
etc...
The problem is, if I would like to use a tenth variable, say it is called 'BLOOD TYPE'. I cannot use:

Code:
BLOOD_TYPE=$10

Bash does not recognize this as 10; rather, it understands it as $1 0 or... BEDFILE10. Is there a way to tell bash to understand $10 and not confuse the '$1' for its already defined usage?

Thanks.
 
Old 07-07-2009, 05:42 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Can you please post more complete code? What you're saying makes no sense.



Cheers,
Tink
 
Old 07-07-2009, 05:44 PM   #3
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
Rather than use every possible positional parameter, look into the shift command. It will allow you to iterate over your arguments, which is a little more graceful.
 
Old 07-07-2009, 05:47 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,716

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
What you look for is
Code:
BLOOD_TYPE=${10}
.
 
Old 07-08-2009, 05:26 AM   #5
jeromeNP7
Member
 
Registered: Jun 2009
Posts: 101

Rep: Reputation: 19
This is a common problem when someone starts out with shell scripting. It makes sense to make it a habit to write input parameters always in the form ${1} to get used to it. Otherwise it is too easy to let such errors like $10 slip into the code and wasting time to sort it out.

Linux

Last edited by jeromeNP7; 09-04-2009 at 10:23 PM.
 
Old 07-08-2009, 10:32 AM   #6
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks guys. Big help.
 
  


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
Storing USB device name in separate variables dynamically. kushalkoolwal Programming 2 01-29-2009 02:05 PM
PHP: storing all data form a db row in variables with the same name as the db column konqi Programming 2 07-10-2008 06:13 AM
another simple unix scripting question! storing values in variables christianunix Linux - Newbie 4 10-30-2007 02:13 PM
Threads synchronisation problem (mutex variables and contitional variables) zahadumy Programming 6 12-07-2005 01:30 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 12:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:50 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration