Search code examples
bashubuntucommandcommand-line-interface

Multiple running bash script 1 command line?


how to run multiple bash scripts in 1 bash command ?

i use command

bash script1.sh

how to make it run multiple commands in 1 command ?

for example

bash script1.sh bash script2.sh bash script3.sh bash script4.sh

Please help


Solution

  • If you want to run all bash script in //:

    for i in {1..4}; do bash "script${i}.sh" & done
    

    If you put the control operator & at the end of a command, e.g. command &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Pid of the last backgrounded command is available via the special variable $!


    If instead you want to run sequentially, use

    printf '%s\n' script{1..4}.sh | xargs -n1 bash
    

    or

    for i in {1..4}; do bash "script${i}.sh"; done