# Basic syntax:
# If you want to run a bunch of shell commands simultaneously, you can
# put them in a file followed by " &" and then bash the file, e.g.:
commands_to_run.txt # contains the following lines:
command 1 &
command 2 &
command 3 &
# Running the file with bash will cause all commands to be run in parallel
bash commands_to_run.txt
# Where this can be practical when you want to build up a set of similar
# shell commands to e.g. process a set of samples.
# Note,
# - in Vim, you can type :%s/^/text to add before/ to add text at the
# beginning of every line and :%s/$/text to add after/ to add text at the
# end of every line.
# Example usage:
# Say you have a directory of files that you want to process in parallel with
# the same shell command. To do this, I'll often do the following:
# Send filenames to a file:
ls /directory/of/files > commands_to_run.txt
# Initial contents of file:
cat commands_to_run.txt
file1
file2
file3
file4
# Prepend and append relevant parts of the command:
vi commands_to_run.txt
:%s/^/beginning of command/
:%s/$/ &/
# Final contents of file:
cat commands_to_run.txt
beginning of command file1 &
beginning of command file2 &
beginning of command file3 &
beginning of command file4 &
# Run all commands in parallel
bash commands_to_run.txt
Add the '&' symbol to the end of your command seperated by a space.
This will put the command in the background and allow bash to continue
running the script.
Example:
#!/bin/bash
command1 &
command2 &
command3