ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.