You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] # test
[[ ]] # test, more flexible than [ ](())# arithmetic evaluation&&# and||# or
Variables
var=10 # dont put spaces in betweenlet x=2
let z=$var+$x# dont use naked variableslet"var+=1"((var +=1))# arithmetic evaluation
I/O
echo"Bash is cool."echo -n "Bash is cool."# does not print newline printf"Bash is cool.\n"read input
Conditionals
if [ condition/expression/command ]
then
command(s)
fi
if [ $a< 10 ];then
command(s)
elif [ $a> 20 ];then
commands(s)
else
commands(s)
fi
file=/home/geek/Documents/doc.txt
if [[ -e$file ]];thenecho"File does not exist."fi
Arithmetic tests are cool
(( a == b ))# [[ $a -eq $b ]](( a != b ))# [[ $a -ne $b ]](( a > b ))# [[ $a -gt $b ]](( a >= b ))# [[ $a -ge $b ]](( a < b ))# [[ $a -lt $b ]](( a <= b ))# [[ $a -le $b ]]
Loops and loop control
forargin [list]
do
command(s)
done
forargin {0..10..1};do
command(s)
done
max=10
for((a=0; a <10; a++))# double parenthesis, and naked "max"do
command(s)
done
while [[ $max< 10 ]]
do
command(s)
done
while(( a < max ))# double parenthesis, and no "$" preceding variablesdo
command(s)
done
whileread input
do
command(s)
if [ condition ];thenbreakdone