LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 08-18-2011, 09:10 AM   #1
kvr2277
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
Unhappy Running a shell file multiple times with different arguments each time in a loop


Hi,

I'm a newbie to shell scripting and am facing the below problem

"I have a shell file run.sh and it has to run multiple times with different arguments passed each time.
Eg:
run.sh abc1
run.sh abc2
run.sh abc3
run.sh abc4
.
.
run.sh abc28"

So, if I consider this in Java terms, it might need a loop programming (for loop?)

Can somebody help me sail through the above problem?
 
Old 08-18-2011, 09:22 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Your mentioning of the for loop is absolutely correct. Tho answer for your question would be:
Code:
for i in {1..28}
do
    run.sh abc$i
done
For more info about bash scripting you might want to have a look at http://tldp.org/LDP/abs/html/.
 
1 members found this post helpful.
Old 08-18-2011, 09:22 AM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Welcome to LQ,

do you mean something like this?
Code:
for i in {1..4}; do
  /path/to/run.sh "abc${i}"
done
You can also use any arbitrary number of arguments to the for-loop:
Code:
for arg in "argument 1" "argument 2" "argument ...";do
  echo "${arg}"
done
Hope this helps.
 
1 members found this post helpful.
Old 08-18-2011, 09:29 AM   #4
kvr2277
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you. LQ is pretty fast.
 
  


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
[SOLVED] [SOLVED]Running a program with arguments using a shell script saskiiaa Programming 1 07-14-2011 03:19 PM
[SOLVED] Passing multiple arguments in shell script dgs012 Linux - Newbie 7 12-11-2010 12:06 PM
Avoid script running multiple times by file lock edenCC Linux - Newbie 6 10-23-2009 06:21 AM
shell script loop though text file:-1 line at a time. knockout_artist Linux - Newbie 2 05-04-2008 06:58 PM
running wget multiple times quickk Linux - Newbie 1 09-16-2004 06:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:49 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