week 7 Flashcards
Brace Expansions
Bash can fill in a pattern contained in braces
I.E echo {1 .. 10 .. 2}
command substitution
allows you to store the output of a command in a variable
ie list = $(ls)
arithmetic expansion
Evaluates a mathematical expression inside
ie $(( arithmetic ))
pattern matching: *
matches any sequence of characters
pattern matching: ?
matches any single character
pattern matching: []
matches any enclosed characters
Declaring function in Bash
function() {
body
}
How do you pass a argument into a bash function?
you must use positional parameters ie $1
Local variables
use the keyword ‘local’ behind what you want to be local scoped only
i.e. local users=$@
How do you return a value in a bash function?
echo what you want to return and assign the return to a new variable
Case
alternative to if/elif/else statements, allows you to patter match possible options and return something different depending
;; = end of condition
| = alternate condition
esac = end
i.e Case expression in:
A)
Echo A
;;
B)
echo B
;;
*)
echo everything
;;
esac
OPTARG
OPTARG contains the arguments used for each flag and is generally used in conjunction with while and case
while getopts “:a:b:” opt; do
case “${opt}” in
a) example=${OPTARG}
esac
done
shift
Shifts positional parameters n characters to the left, shift can stack with each other
what is YAML?
“YAML ain’t markup language”, a human readable, data serialization language
What command do you use to quit a process?
kill