Launch shell script from another script [duplicate] - bash

This question already has an answer here:
Running several scripts in parallel bash script [duplicate]
(1 answer)
Closed 7 years ago.
I have the following shell script
#for i in {0..10}
do
run my command that takes about 10 seconds with parameter $i
done
How can I get this to run the commands in parallel without using GNU Parallel as I am not able to install it on my linux box.
Is there a way I can create 10 different shell scripts and call them e.g. script_1.sh, script_2.sh, script_3.sh etc and then launch them one by one from this script?

You could use an ampersand (&) and launch script.sh $1 & ten times. This will make the script run in a fork of the main process. It is an easy way to do parallel processing but definitely not very flexible and doesn't have many features. A simple tutorial can be found here.

Related

Ways to execute bash script without "./"? [duplicate]

This question already has answers here:
How do I run a shell script without using "sh" or "bash" commands?
(13 answers)
How to enable a system-wide function for users including sudo?
(2 answers)
Closed 3 years ago.
I have a bash script called climb.sh. When I execute it I write
./climb.sh 1
while inside the directory in which the script is located. However, I want to do the same thing wherever I am, and across all shell sessions by simply calling
climb 1
Also, climb.sh takes an numeric argument and calls "cd ../" that many times. In order for the program to work, it has to run alongside the current process, not within some child process.
How to achieve all this?
Thanks

bash script, execute command line and keep going the next for loop [duplicate]

This question already has answers here:
Loop background job
(3 answers)
Closed 4 years ago.
Is it possible to run a command in a for loop without waiting for that command ended, while keeping going to the next iteration?
Because I have to send multi-files at the same time asap via many ssh connections, therefore I couldn't wait until the command ended one by one.
Maybe is it related to something like 'xterm' or 'gnome-terminal'?
Yes, you can execute the command in background by adding & at its end.
So the syntax looks like programName [arguments] & (at least for bourne compatible shells)

why bash shell does not make any difference after executed? [duplicate]

This question already has answers here:
Global environment variables in a shell script
(7 answers)
Closed 5 years ago.
I'm working a small project which needs using OpenMPI to make "mpicc" work.
I made a file make_cmd:
#!/bin/bash
module load OpenMPI
However, after executing ./make_cmd, I was told:
mpicc: command not found
But if I just type on the command line: module load OpenMPI, then mpicc is working.
Why is that? Thanks!
See this answer on neighbouring site.
Because module is an alias/shell function and not a binary program, it's not necessarily available in the non-interactive sub-shell that is created when you run your script. You could probably run source make_cmd though, as that will just run the commands in your current interactive shell. You could ditch the #!/bin/bash line in that case.

Run in parallel from bash [duplicate]

This question already has answers here:
How do you run multiple programs in parallel from a bash script?
(19 answers)
Closed 6 years ago.
I have this bash script:
#!/bin/bash
for i in `seq 1 10`;
do
./Hysto file$i.txt
done
I am completely new to parallel programing and even bash language but i meant by this code to run 10 jobs in parallel (I have more than 10 cores available). The program in meant to save data to some files (which don't depend on each other). However in the folder where the files are supposed to be created they appear one by one (the output of file1.txt, then file2.txt and so on), so I assume they are not run in parallel. Can you tell me how can I write a bash file so I can run my jobs in parallel?
All you need to do to run in parallel in bash is to put an & at the end of your command. Here you'd put it after .txt.
See also: How do you run multiple programs in parallel from a bash script.

Regarding operation flow in a bash script [duplicate]

This question already has answers here:
bash script order of execution
(2 answers)
Closed 7 years ago.
I was just wondering, in a bash script, if I have a command on one line to say rsync a large file (~10GB) then the next command on the next line is meant to rename then move that same file, will the script know to wait for the rsync to complete before attempting the rename and move?
Is there a flag or something I can put on each line to make it wait before executing the next command?
Sorry if this seems like a total noob question, but alas I am a noob!
Thanks in advance for any info!
All commands are executed in sequence, so, a command will wait for the previous command to complete. Only when you add a & to the end of a command will it run in the background, and thus not wait for completion before executing the next.

Resources