1

I would like to queue some bash scripts on a file that I can modify. So that I launch that file "lauchscripts.py" or "lauchscripts.sh" which contains the commands for launching the scripts:

1:> source folder1/script1.sh 
2:> source folder2/script2.sh
3:> source folder3/script3.sh 
4:>

So that: 1) when I launch this, it launches script1.sh, then when it finishes it launches script2.sh and so on. 2) at anytime while running,I can add lines to my "lauchscripts" file that will be later executed. Let's say while running script3.sh (line 3), if I add at line 4 a command:

1:> source folder1/script1.sh 
2:> source folder2/script2.sh
3:> source folder3/script3.sh 
4:> source folder4/script4.sh

This line will execute script4.sh after finishing script3.sh

Is that possible?

Thanks

0

If your file contains the names of the scripts themselves rather than code, you can do this easily and safely:

while read -r -u 9
do
    . "$REPLY"
done 9< scripts.txt

As with most scripting hacks, there are a lot of caveats to this (and even more if you read code and eval it):

  1. If file descriptor 9 (-u 9) is used for anything in any of the scripts all bets are off.
  2. If any of the scripts set any variables this context not be cleared out.
  3. Once the last line of scripts.txt is read the loop finishes.

A better solution would be to run the scripts you read, by simply removing the dot. For this to work the script paths need to contain at least one slash or else the scripts need to be on your PATH.

  • I tried it, and it look like when running the while read code, it reads all in once, instead of reading as executing. Hence changing scripts.txt while running your lines, won't affect what will be run. – nikarko01 May 30 '18 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.