LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-28-2012, 05:07 AM   #1
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Rep: Reputation: Disabled
Unhappy Passing Single Argument to Multiple Scripts


I have 12 scripts in a single folder. And i need to pass 'dry' as a parameter to each of this scripts. But i want to pass 'dry' parameter to first script then wait for it to complete its execution. Then i need to start the second script again using dry as parameter and so on.

The 12 files are named as follows-
01-xxx.sh
02-xxx.sh
03-xxx.sh
.
.
.
.
.
.
10-xxx.sh
.
12-xxx.sh

I wanna do like below-

> sh 01-xxx.sh dry
> wait for its execution to finish

> sh 02-xxx.sh dry
> wait for its execution to finish and so on for the remaining scripts

Can anyone provide me the solution for the above problem?
 
Old 02-28-2012, 05:23 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I don't see a problem to fix here really. You want to run them automatically one after another? You can easily just put them in a script, one after another. If you want to avoid just typing "dry" in 11 saves, just put "$1" as the parameter on each line and pass that as a parameter to the noddy script.

Code:
#!/bin/bash
01-xxx.sh $1
02-xxx.sh $1
03-xxx.sh $1
and then run
Code:
# sh myscript.sh dry
 
Old 02-28-2012, 05:33 AM   #3
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
how about
Code:
for i in ./{01..12}-xxx.sh; do $i dry; done
 
1 members found this post helpful.
Old 02-28-2012, 05:49 AM   #4
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Original Poster
Rep: Reputation: Disabled
How to control the execution of the scripts based on time and memory constraints?

How to find out the time and memory requirement of a script?
 
Old 02-28-2012, 05:50 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Well that's nothing in the slightest bit related to what you originally asked, is it?

This is reading a lot like homework to me now, and we aren't here to prevent you having to learn.
 
1 members found this post helpful.
Old 02-28-2012, 06:05 AM   #6
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Original Poster
Rep: Reputation: Disabled
Hey that is the next step i need to implement in my code. It just that i wanna control the execution of those scripts so that segmentation issues do not arise as these are memory intensive scripts.

I am going slow so that i can grasp the logic and will put it together all at once.

Hope its OK........
 
Old 02-28-2012, 06:41 AM   #7
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Original Poster
Rep: Reputation: Disabled
Red face

Quote:
Originally Posted by millgates View Post
how about
Code:
for i in ./{01..12}-xxx.sh; do $i dry; done
I am not able to execute this loop. Its showing some error.

can you modify the code if my scripts are named as below-

01-bwa.sh
02-resolvemerge.sh etc

Keep in mind that the naming starts with 01 and ends to 12.

i think your loop is just taking 1-bwa.sh and not 01-bwa.sh. Please modify the logic as per my needs.

thanks in advance....
 
Old 02-28-2012, 06:45 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Surely a loop is just a nice little bonus? You have twelve lines, just type them out...??
 
Old 02-28-2012, 06:49 AM   #9
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
the
Code:
./{01..12}-xxx.sh
was based on an assumption that your scripsts follow the 01-xxx.sh naming scheme and could be generalized to

Code:
./{01..12}-*.sh
but be careful with that because it might also match something you don't want it to match
 
Old 02-28-2012, 06:59 AM   #10
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by millgates View Post
the
Code:
./{01..12}-xxx.sh
was based on an assumption that your scripsts follow the 01-xxx.sh naming scheme and could be generalized to

Code:
./{01..12}-*.sh
but be careful with that because it might also match something you don't want it to match
After running the loop i am getting the following error-

-bash-3.2$ for i in ./{01..12}-*.sh; do ./$i dry; done
-bash: ././1-*.sh: No such file or directory
-bash: ././2-*.sh: No such file or directory
-bash: ././3-*.sh: No such file or directory
-bash: ././4-*.sh: No such file or directory
-bash: ././5-*.sh: No such file or directory
-bash: ././6-*.sh: No such file or directory
-bash: ././7-*.sh: No such file or directory
-bash: ././8-*.sh: No such file or directory
-bash: ././9-*.sh: No such file or directory

Why its taking 1-*.sh and not 01-*.sh?
 
Old 02-28-2012, 07:57 AM   #11
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
That's because you are using bash-3.2, which does not support leading zeroes in brace expansion. It works correctly in bash-4.x, though.
This might work for you:

Code:
for i in {1..12}; do $(printf "./%02i-*.sh*" $i) dry; done
assuming that the numbers 01..12 will match only one file in your current directory each

Last edited by millgates; 02-28-2012 at 07:59 AM.
 
1 members found this post helpful.
Old 02-28-2012, 08:00 AM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
seriously... overkill anyone?
 
Old 02-28-2012, 08:20 AM   #13
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by millgates View Post
That's because you are using bash-3.2, which does not support leading zeroes in brace expansion. It works correctly in bash-4.x, though.
This might work for you:

Code:
for i in {1..12}; do $(printf "./%02i-*.sh*" $i) dry; done
assuming that the numbers 01..12 will match only one file in your current directory each
Thank you so much. The loop is working and i really appreciate your effort to help me.
 
Old 02-29-2012, 06:49 AM   #14
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by millgates View Post
Code:
for i in {1..12}; do $(printf "./%02i-*.sh*" $i) dry; done
The command seq could save the printf:
Code:
for i in $(seq -w 12); do ./$i-*.sh dry; done
 
1 members found this post helpful.
  


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 string as a single argument in shell script sinoob Linux - General 3 09-14-2011 03:21 AM
Makefile - passing argument to make? gayleard Linux - Software 1 03-06-2010 06:14 PM
simple argument passing tostay2003 Linux - Software 7 09-13-2006 04:11 PM
segfault when passing array[] as argument froboozle Programming 11 06-28-2005 03:06 PM
passing function pointer as argument worldmagic Programming 7 08-04-2004 03:33 PM

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

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