I have a number of bash scripts. for example
script1_1.sh
script1_2.sh
script1_3.sh
etc….
I was wondering, is there a way for me to run these all in another script. where by I don’t have to manually add each. So through the use of a for loop? where it increments a number like
for (i=0; i < 40; i++)
./script1_[i].sh
I would also like to check each script worked, so if not, it would exit the for loop.
if ./script[i] (command unsuccessful)
then break?
Can anyone help me write this code? i’m very new to scripting languages.
You are really close to answering your own question. The C-style for loop will work fine for your scenario, but if your scripts are randomly named, you can use an array. You can use
||, which will execute the right side if a non-zero exit status is returned. You could also use an if statement like you have proved in your question, with a “!” between if in the command (if not).Using the for loop like in your questions: