LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Passing Single Argument to Multiple Scripts (https://www.linuxquestions.org/questions/programming-9/passing-single-argument-to-multiple-scripts-931716/)

prravin1 02-28-2012 05:07 AM

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?

acid_kewpie 02-28-2012 05:23 AM

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

millgates 02-28-2012 05:33 AM

how about
Code:

for i in ./{01..12}-xxx.sh; do $i dry; done

prravin1 02-28-2012 05:49 AM

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?

acid_kewpie 02-28-2012 05:50 AM

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.

prravin1 02-28-2012 06:05 AM

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........

prravin1 02-28-2012 06:41 AM

Quote:

Originally Posted by millgates (Post 4613956)
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....

acid_kewpie 02-28-2012 06:45 AM

Surely a loop is just a nice little bonus? You have twelve lines, just type them out...??

millgates 02-28-2012 06:49 AM

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

prravin1 02-28-2012 06:59 AM

Quote:

Originally Posted by millgates (Post 4614037)
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?

millgates 02-28-2012 07:57 AM

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

acid_kewpie 02-28-2012 08:00 AM

seriously... overkill anyone?

prravin1 02-28-2012 08:20 AM

Quote:

Originally Posted by millgates (Post 4614086)
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.

Reuti 02-29-2012 06:49 AM

Quote:

Originally Posted by millgates (Post 4614086)
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


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