LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-03-2007, 12:05 PM   #1
echat
Member
 
Registered: Nov 2006
Distribution: Kubuntu 9
Posts: 34

Rep: Reputation: 16
Unhappy Bash Help


Ok, I have not done anything in bash for the past 5 months. Mostly because I have been working c++. I am trying to print an arg list. cant remember how the hell to run through args. I thought it was a for statement but I can't remember if there is an array that holds the agrs. I do remember that the agrs are set up as $1, $2, $3,etc,.... any help would be great.

Last edited by echat; 07-03-2007 at 12:07 PM.
 
Old 07-03-2007, 12:16 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
$1 is "bashese" for the first argument passed in to a script.

One way to iterate thru a set of values is the for loop--e.g.:
for i in <list>
do
something
done

Where <list> can be a literal list, or the output of some other command (using--eg--backtics)

What book do you use for BASH and scripting? Some good references are listed here:
http://www.linuxquestions.org/questi...d.php?t=566095
 
Old 07-03-2007, 12:24 PM   #3
echat
Member
 
Registered: Nov 2006
Distribution: Kubuntu 9
Posts: 34

Original Poster
Rep: Reputation: 16
I actually don't have any of my scripting books anymore. Lost them in the move.

Last edited by echat; 07-03-2007 at 12:44 PM.
 
Old 07-03-2007, 12:37 PM   #4
card-suse
Member
 
Registered: Dec 2005
Location: Ohio, USA
Distribution: OpenSuSE 10.2
Posts: 74

Rep: Reputation: 15
Quote:
Originally Posted by echat
Ok, I have not done anything in bash for the past 5 months. Mostly because I have been working c++. I am trying to print an arg list. cant remember how the hell to run through args. I thought it was a for statement but I can't remember if there is an array that holds the agrs. I do remember that the agrs are set up as $1, $2, $3,etc,.... any help would be great.

The variable $@ expands all the positional arguments. So
Code:
echo $@
should print all the positional arguments. Is this what you were wanting? If you have options you are trying to parse, then you need to use the getopts construct. Do you want the syntax for that?
 
1 members found this post helpful.
Old 07-03-2007, 12:41 PM   #5
echat
Member
 
Registered: Nov 2006
Distribution: Kubuntu 9
Posts: 34

Original Poster
Rep: Reputation: 16
No thank you for that. I just need to run through a for statement. Thank you for this.

Code:
for i in $@; do echo $i; done
^ is just what I needed :]

Last edited by echat; 07-03-2007 at 01:39 PM.
 
  


Reply



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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Bash development - move chmod options to bash jhwilliams Programming 9 06-26-2007 12:13 PM
Bash Sleep vs crontab and bash serial port nutthick Programming 4 06-01-2006 02:42 AM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:50 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
Open Source Consulting | Domain Registration