Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 75 lines (74 sloc) 1.59 KB
#!/bin/bash
# SEE THIS LIST FOR ALL EXPRESSIONS: http://bit.ly/HrSdCQ
# STRINGS: s1 = s2 | s1 != s2 | s1 < s2 | s1 > s2 | -n s1 (not null) | -z s1 (is null)
# ARITHMETICS: i1 -lt i2 (<) | i1 -gt i2 (>) | i1 -le i2 (<=) | i1 -ge i2 (>=) | i1 -eq i2 (==) | i1 -ne i2 (!=)
# SCRIPT SHALL IMMEDIATELY ABORT ON ERROR
set -e
# FOR LOOP
for i in $( ls ); do
echo item: $i
done
# ONE LINE FOR LOOP
for i in $( ls ); do echo item: $i; done
# FOR LOOP (C STYLE)
for ((x = 0 ; x <= 100 ; x++)); do
echo "Counter: $x"
done
# WHILE LOOP
COUNTER=0
while [ $COUNTER -lt 10 ]; do
echo The counter is $COUNTER
let COUNTER+=1
#or c-style ((COUNTER++))
done
# UNTIL LOOP
COUNTER=20
until [ $COUNTER -lt 10 ]; do
echo COUNTER $COUNTER
let COUNTER-=1
done
# IF THEN ELSE
if [ "42" = "41" ]; then
echo expression in if evaluated as true
elif [ "32" = "32" ]; then
echo expression in elif evaluated as true
else
echo expression evaluated as false
fi
# SWITCH
case $VAR in
value1)
#on value1
;;
value2)
#on value2
;;& #falls trough
*)
#on default
;;;
esac
# FUNCTION
function myFunc {
echo $1
}
myFunc "Hello World"
# or catch the output
RETURNVAL=$(myFunc "Hello World")
# PIPE
ls -l | sed -e "s/[aeio]/u/g"
# ECHO
echo text with newline
echo -n omit newline
# GREP CAN READ FILES
grep "READ FILES" basics
# ARRAY (whitespace separated!!)
COLORS=('Blue' 'Red')
echo ${COLORS[0]}
# length
${#COLORS[@]}
# REG EXP: sed -or- egrep (grep -e)
# CALCULATION INT
let "SUM=1+2" #OR: echo $((1+2))
echo $SUM
# CALCULATION FLOAT
bc -l <<< "1.1+2.2"