How to run a sequence of scripts?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run a sequence of scripts?
# 1  
Old 12-10-2016
How to run a sequence of scripts?

Assume I want to run a sequence of scripts:

Code:
script0001.sh
script0002.sh
script0003.sh
...
script0122.sh
script0123.sh

I only know a little Linux scripting, so the following is the best I can write

Code:
for k in $(seq 1 123)
do
   ./script${k}.sh
done

Of course it doesn't work because I don't know how to pad zeros. Could you please help me with it? Thanks a lot!

Last edited by Scrutinizer; 12-11-2016 at 03:46 AM..
# 2  
Old 12-10-2016
Without knowing what shell you're using, it is hard to give the most efficient way to do this. A portable way that will work with any shell that provides features required by the POSIX standards would be:
Code:
i=1
while [ $i -le 123 ]
do	cmd=$(printf './script%04d.sh' $i)
	$cmd
	i=$((i + 1))
done

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 12-11-2016
In bash version 4 and up on Linux/Unix you can also do this:
Code:
for scr in script{0001..123}.sh
do
  ./scr
done

This also works in zsh

Last edited by Scrutinizer; 12-11-2016 at 04:09 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To run multiple scripts

Hi , Can someone help! I need a shell script to run multiple scripts by using single shell script, incase any one of the scripts fails, it should get exit and after trouble shooting if we re-execute it, it should start from the failed script (4 Replies)
Discussion started by: anniesurolyn
4 Replies

2. Shell Programming and Scripting

Run scripts in background one by one

Hello all, Can someone help with one script? I have as example 3 scripts 1.sh sleep 60 & sleep 60 & sleep 10 & sleep 80 & sleep 60 & 2.sh sleep 40 & sleep 5 & sleep 10 & sleep 70 & sleep 60 & 3.sh (2 Replies)
Discussion started by: vikus
2 Replies

3. Shell Programming and Scripting

Help with writing a script to run java commands in sequence in UNIX

Hi, Brand new to these forums, and I hope that someone can help me out. I'm trying to run the following command in UNIX java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my.bam --outputRoot /my/path/SampleFiles/Sample_ It executes the SplitSamFile from GATK, but I... (3 Replies)
Discussion started by: Wixaros
3 Replies

4. UNIX for Dummies Questions & Answers

Scripts can be run manually but couldn't run with cronjobs

I am from MQ/MB technology. My requirement is to display the queue manger and broker status on daily basis. If I manually run the script, it works fine and displays output. But when I have scheduled the same using cronjobs it shows only the queue manger status and not the broker status. Can... (3 Replies)
Discussion started by: Anusha M
3 Replies

5. Shell Programming and Scripting

background scripts run-help

Looking for a logic where say i have a script called parent_script which is used to call other 4 to 5 child scripts in background as.. cat parent_script # containing 65 lines 1 2 .. 35 while read child_script 36 do 37 ./child_script_name& 38 done< ${SCRIPT_LISTS} 39 40 # Need to have... (2 Replies)
Discussion started by: michaelrozar17
2 Replies

6. Shell Programming and Scripting

how to run scripts....

I am going to run the scripts (filetest.sh) Its run with..... ./filetest.sh sh filetest.sh but not run with..... filetest.sh ( giviing error command not found) tell me the way how we can do it ? (6 Replies)
Discussion started by: ani83_pune
6 Replies

7. Shell Programming and Scripting

telnet and run scripts

Hello folks, I've got this script which connects to different boxes and executes a certain script in those locations. The following is the line from where i am trying to do this: (sleep 1; echo $USERID ; sleep 1; echo $PASSWD ; sleep 1 ; echo y ; sleep 1 ; echo "\r" ; sleep 1 ; echo "cd... (1 Reply)
Discussion started by: Rajat
1 Replies

8. AIX

To run scripts

How to run a script from any directory? Should i include any environment or wat should i start with in writing a script ? (1 Reply)
Discussion started by: rollthecoin
1 Replies

9. Shell Programming and Scripting

Can't get Cygwin to run scripts

I haven't been on a unix system in a long time and I'm trying to teach a friend unix. After looking at/testing various options cygwin seemed to be the easiest to download and install. Everything works pretty much as I recall and I even tested a small java program on it. I can't seem to get... (4 Replies)
Discussion started by: mmtemp
4 Replies

10. Shell Programming and Scripting

Run scripts within a script..

Hi all... I have several scripts of varying types (shell script, expect script, awk script) that I would like to run within 1 script.. They also take a command line argument (which it is getting successfully). The problem is, the parent script is exiting after the first script it calls is... (2 Replies)
Discussion started by: earnstaf
2 Replies
Login or Register to Ask a Question