[Color Codes] Environmental Variables: PATH What is path? PATH=$PATH:/MyFolder/YourStuff?Scripts ENV HOME PWD SHELL PS1 EDITOR Showing default text editor
#!/bin/bash a=375 hello=$a #No space permitted on either side of = sign when initializing variables. # VARIABLE =value Script tries to run VARIABLE command with one argument, =value. # VARIABLE = value #Script tries to run value command with the environmental variable VARIABLE set to. echo hello #hello echo $hello #375 echo ${hello} #375
Quoting Variable Enclosing a referenced value in double quotes (... ) does not interfere with variable substitution. This is called partial quoting. ( ) causes the variable name to be used literally. echo $hello #375 echo ${hello} #375 hello= AB C D echo $hello #ABCD echo $hello #AB C D #Quoting a variable preserves whitespace echo $hello #$hello # Setting multiple variables on the same line var=21 var2=22 var3=$v3 hello = #setting it into a null value echo \$hello (null value) = $hello #$hello (null value) = #Note that setting a variable to a null value is not the same as unsetting it, although the end result is the same numbers= one two three other_numbers= 1 2 3 If there is a white space embedded with a variable, then quotes are necessary. other_numbers=1 2 3 # Gives an error message echo numbers=$numbers #number=one two three echo uninitialized_variable = $uninitialized_variable
# Uninitialized variable has null value (no value) uninitialized_variable= # Declaring, but not initializing it, same as setting it to a null value, as above. echo uninitialized_variable = $uninitialized_variable #It still has a null value uninitialized_variable=23 #set it. unset uninitialized_variable #Unset it. echo uninitialized_variable = $uninitialized_variable # uninitialized_variable = it still has a null value echo $uninitialized #(blank line) let uninitialized = $uninitialized +5 [next two bullets] pg 8 The Bash escape sequences: Escaping is a method of quoting single characters. The escape (\) preceding a character tell the shell to interpret that character literally \n means newline \r means return \t means tab \v means vertical tab \b means backspace \a means alert (beep or flash) \0xx translates to the octal ASCll = of Onn, where nn is a string of digits
Bash Shell Operators Comparison Operators Bash Tests Arithmetic Operators Assignment Operators Logical and Bitwise Operators eq is equal to if[ $a eq $b ] ne is not equal to if[ $a ne $b ] gt is greater than if[ $a gt $b ] ge is greater than or equal to if[ $a ge $b ] lt is less than if[ $a lt $b ] le is less than or equal to if[ $a le $b ] Double Parenthesis
< is less than (( $a < $b )) <= is less than or equal to (( $a <= $b )) > is greater than (( $a > $b )) >= is greater than or equal to (( $a >= $b )) = is equal to if[ $a = $b ] == is equal to if[ $a == $b ]!= is not equal to if[ $a!= $b ] This operator uses pattern matching within a [[ ]] construct. ASCll alphabetical < is less than if[ $a \< $b ] if[[ $a < $b ]] Bash Test Bash has the test command: if [ condition true] if [ condition1 ] then then command2 command2 else fi command2 elif [ condition2 ] then command2 else fi
#!/bin/bash if [ foo = foo ]; then echo expression evaluated as true fi #!/bin/bash T1= foo T2= bar if [ $T1 = $T2 ]; then echo expression evaluated as true else echo expression evaluated as false fi