BASH

# and
if [ "$foo" == "a" ] && [ "$bar" == "b" ]; then
 
 # or
if [ "$foo" == "x" ] || [ "$bar" == "y" ]; then
 
# both
if ( [ "$a" == "a" ] || [ "$a" == "b" ] ) && ( [ "$b" == "c" ] ); then
 
 
# enable color output systemwide for ls and grep
cat <<EOF>> /etc/profile.d/alias.sh
alias ls='ls --color=auto'
alias grep='grep --color=auto'
EOF
 
# get exitcode prevoius command
${PIPESTATUS[0]}
 
# redirect stdout AND stderr to file
COMMAND &> file.out
 
# sequence
echo {,my-}host{1,{3..5},9,10}
echo $(seq 1 4)
 
# for loop
START=1
END=10
for ((i=START; i<=END; i++)); do
    echo "i: $i"
done
 
# String regexp
if [[ "${MOTHERBOARD}" =~ H8DM(8|E)-2 ]] &&  [[ "${RAID}" =~ 9650SE-(4|8)LPML ]]; then
   echo "found"
fi
 
# replace commas with spaces
${foo//,/ }
 
# endless loop
while true; do
  YOUR_COMMAND
done
 
# read from standard input
IN=$(cat /dev/stdin); echo $IN
 
# process specified files in directory
for i in *.$1
do
	 echo "$i" "${i%$1}$2"
done
 
# ping all clients
NET=192.168.1
for i in {1..254}; do
   ping  -w 1 -c 1 ${NET}.$i > /dev/null
 
   if [ $? -eq 0 ]; then
      echo ${NET}.$i
   fi
done
 
# parameter expansion
echo ${variable:-default_value}
 
#
# shell variables
#
# internal field separator
IFS=$(echo -en "\n\b")
 
# get calling (parent) script name
CALLING_SCRIPT=$(ps -o command= $PPID)
SCRIPT=${CALLING_SCRIPT##*/}
 
# ssh interactive login
ssh foo@www.example.com -t "bash -ic 'bar -vvv'"
 
# uppercase
x=bar
echo ${x^}
Bar
echo ${x^^}
BAR
 
# lowecase
x=BAR
echo ${x,}
bAR
echo ${x,,}
bar
 
# LINKS
https://www.dartmouth.edu/~rc/classes/ksh/special-vars.html
http://wiki.bash-hackers.org/commands/classictest - BASH test commands
http://www.linuxtutorialblog.com/post/tutorial-conditions-in-bash-scripting-if-statements