#!/bin/bash or #!/usr/bin/bash
# anything following a hash symbol
echo "Hello world."
variable_name=value declare variable_name=value name="John Smith" x=5
export VARIABLE_NAME=value export PATH=/bin:/usr/bin:. declare -x VARIABLE_NAME=value
echo $variable_name echo $PATH
echo "Enter your name (first and last):" read wholename read firstname lastname
echo $1 $2 $3 # individual arguments echo $* # all arguments echo $# # number of arguments
declare -a array_name=(word1 word2 word3 ...) declare -a fruit=(apples pears plums) echo "I like to eat" ${fruit[0]}
somevar=`command`; somevar=$(command) echo $somevar # show result of command echo "Today is `date`" echo "Today is $(date)"
declare -i variable name # integer variable declare -i ii=44+44 (( n= 5 + 5 )) echo $ii $n
if command then block of statements fi if [[ expression ]] then block1 else block2 fi if (( numeric expression )) then block1 else if (( another expression) then block2 elif [[ boolean expression ]] then block3 fi if (( 3+3 )); then echo yes; fi
case variable_name in pattern1) statements ;; pattern2) statements ;; pattern3) ;; esac case "$color" in blue) echo $color is blue ;; red|orange) echo $color is red or orange ;; *) echo not a match ;; esac
while [[ string expression ]] do block of statements done until command do block of statements done
for variable in word_list do block of statements done for color in red green blue do echo $color done select variable in word_list do block done select fname in red green blue; do echo you picked $fname \($REPLY\) break; done
function_name() { block of code } function function_name { block of code } ... function_name