======
https://guide.bash.academy/expansions/
bash wraps the kernel so you can launch processes
if [ -r 1 ] && [ -s 2 ]
if [ $USER == 'bob' ] || [ $USER == 'andy' ]
for i in $(cat countries.txt); do
echo -n ${i:0:1} | tr '[:lower:]' '[:upper:]';
echo ${i:1};
done >> countries.txt
for i in $(seq 1 10); do echo $i; done
for ((i=1;i<10;i++)); do echo $i; done
if [ <test> ]; then echo foo; fi
if [ <test> ];
then
echo 1;
elif [ <test2> ];
then
echo 2;
else
echo 3;
fi
if [ -d <directory> ];
if [ -f <directory> ];
if [ -L <directory ];
case $1 in
start)
echo start;;
stop)
echo stop;;
restart)
echo restart;;
*)
echo no clue;;
esac
while [ <test> ]; do echo 1; done
<file while read; do echo "$REPLY"; done
<file while read line; do echo "$line"; done
if [[ $REPLY = y ]]; then echo 1; fi
matches any text or no text
matches a single character
matches single character as long as its within the set
alnum, alpha, ascii, blank, cntrl, digit, graph, lower, print, punct, space, upper, word, xdigit
Expands to current user's home directory (i.e. /home/user)
When multiple patterns are needed to be used.
Matches when any of the patterns appears at least once
Matches when patterns appear at least once or not at all (what the heck?)
Matches once or not at all
Matches when any of the patterns appear exactly once
Matches only when none of the patterns appear
ls *.jp?(e)g
ls *.@(jpg|jpeg)
Launches command in subshell (new bash process)
cat /etc/passwd
Deprecated syntax for same thing
echo "My name is $name"
echo "Contents here: ${contents}<--end of file"
echo "$name's current record is ${time%.} seconds and ${time#.} hundredths."
echo "PATH currently contains: ${PATH//:/, }"
Remove the shortest string that matches pattern (start) "${url#*/}" /www.hooperlabs.xyz/h00p.html
Remove the shortest string that matches the pattern (end) "${url%/*}" https://www.hooperlabs.xyz
Remove longest string matching pattern (end) "${url%%/*}" https:
Replace first string matching pattern "${url/./-}" https://www-hooperlabs.xyz/h00p.html
Replace each string matching pattern "${url//./-}" https://www-hooperlabs-xyz/h00p.html
Replace string matching pattern (start) "${url/#*:/http:}" http://www.hooperlabs.xyz/h00p.html
Replace string matching pattern at end "${url/%.html/.jpg}" https://www.hooperlabs.xyz/h00p.jpg
Expand length of the value (in bytes) "${#url}" 36
Expand part of value starting at start, length bytes long "${url:7}" www.hooperlabs.xyz/h00p.html
Expand the transformed value, either upper or lower (first char or all chars) of string that matches the pattern. "${url^^[ht]}" HTTps://www.Hooperlabs.xyz/h00p.HTml
Substitute : for spaces in $PATH.
numbers in sequence (separated by spaces)
count by twos
first positional parameter
expands single string, joining all parameters into one, separated by $IFS
expands the positional parameters as a list of separate arguments
expands into a number indicating the number of positional parameters
expands the exit code of last command (0 means success)
expands the set of option flags currently active in shell
expands PID for current shell process
expands unique PID foir last process started in background
expands to the last argument of previous command
expands to full previous line
expands to second argument of last command
second command in history
all but first argument of last command
current working directory
old working directory
full pathname of command that started the current bash shell
active version of bash
array of detailed info about current version of bash
filenames of the scripts currently running (usually empty)
PID of the bash that is parsing script code
uid of user within bash shell
pathname of the home directory
name of computer
preferred language category
full description of type of system
pathname to current directory
pathname of directory you were in before
expands random number between 0 and 32767
number of seconds bash shell has been active
contains height (rows) of terminal display
contains width (single char spaces) of single row in display
"Internal Field Separator" - bash uses this for word-splitting of data. By default, spaces, tabs, and newlines
List of paths bash will search for executable programs when a command is run.
Contains string that describes what the prompt should look like
describes what the secondary prompt will look like
files=( myscript hello.txt "foo bar.txt" ); rm -rv "${files[@]}"
Use quotes around array!!! don't use ${files[@]}
files+=( selfie.png )
files=( *.txt )
echo "${files[0]}"; echo "$files"
unset "files[3]"
echo "${#files[@]}"
echo "${names[@]:1:2}"; echo "${names[@]: -2}"
sed -n -e '/BEGIN/./END/ p'
sed -e 1d -e s/foo/bar/g /tmp/foo
sed '1d; s/foo/bar/g' /tmp/foo
sed -i '/192.168..1/d' /var/log/apache2/access.log
echo a,b,c,d,e | awk -F, '{print $1 $2 $3 $5}'
grep -a "SearchMe" /dev/sd*