Lect18 - Advanced Bash Flashcards
What is Bash?
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 distributed widely as the default login shell for most Linux distributions and Apple’s macOS (formerly OS X). A version is also available for Windows 10
What are environment variables?
Bash stores a number of variables that control the way it operates. Some are system default. Many can be set by the user to adjust the operating environment. These can be displayed with the env command.
How can you display shell variables?
# echo $USER
or
# echo $LANG
How can you assign value to custom variable?
# fruit=apple
then
# echo $fruit
the variable is available ONLY in the current shell.
How can you make variable globally available?
# export fruit=apple
How can you substitute the output of a command for a variable
md5 = $(md5sum MyEvid.raw)
Show basic usage of a for loop?
$ for item in list
do
action on $item
done
Run a command for any txt file found?
for x in $(find . -name ‘*.txt’)
do
file $x
done
How can you execute multiple commands without interrupt?
echo 1; echo 2; echo 3;
How can you execute multiple commands, but only if preceding command is successful?
echo 1 && echo 2 && echo 3
dd if=/dev/sdh of=sdh.raw && md5sum sdh.raw
You want to view all pictures in a directory without having to use a separate command for each?
for pic in ./*
do
xv $pic
done