BASH (Bourne Again SHell)
Introduction
BASH is the default command interpreter for most Linux distributions. According to Wikipedia...
Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used as the default login shell for most Linux distributions. Bash was one of the first programs Linus Torvalds ported to Linux, alongside GCC.
Ranges
touch file-{1..8}.txt
This touches 8 seperate files of name file-1.txt
through file-8.txt
.
For each in Loop
for file in *; do echo $file; done
# OR
for file in *;
do
echo $file;
done
By using the
for SOME_VAR in SOME_MULTILINED_OR_GLOB; do SOME_CMDS; done
pattern you can loop through every item in
a multiline (how bash knows something is a collection),
collection of entities and perform a set of commands on each of them individually.
Kind of like the for some_var in some_collection
in Python.
This could also be modified to perform this action on a range.
for num in {1..8}; do echo $num; done;
This for loop uses the for-in
loop structure and
the {x..y}
range structure to create a range of inputs to
loop through echo'ing the numbers 1 through 8 in their own line.
The glob pattern shown above can also be changed when
specifying the for loop as it's often used for files to
only iterate through some pattern, say only .jpg
files.
for file in *.jpg; do echo $file; done