if [ $UID -eq 0 ];then echo "root";fi
ping -c 1 ${HOST} -W 1 >/dev/null if [ $? == 0 ]; then fi
clr_red=$'\e[1;31m' clr_green=$'\e[1;32m' clr_yellow=$'\e[1;33m' clr_blue=$'\e[1;34m' clr_reset=$'\e[0m'
echo ${clr_red}test${clr_reset}
log single command (only stderr) and view simultaneously (stdout+stderr)
#via Process Substitution (https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution) make 2> >( tee "$logfile" ) ; echo $?
log multiple lines/commands:
exec 3> >(tee logfile) make alpha 2>&3 && make bravo 2>&3 && make charlie 2>&3 && success=1 exec 3>&-
case "$string" in *foo*) #anything ;; [1-6]*) #number-ranges ;; *) #all other ;; esac
$ VAR=/home/me/mydir/file.c $ DIR=$(dirname "${VAR}") $ echo "${DIR}" /home/me/mydir $ basename "${VAR}" file.c
a=string b=${a:p:l} #p=Position (0-basiert),l=Länge
orig="AxxBCyyyDEFzzLMN" mod=${orig//[xyz]/_}
string='My string'; if [[ $string =~ .*My.* ]] then echo "It's there!" fi
GPIO_NO=$((232+25))
ls IMG_20170923_{17..18}*
temporary change language (e.g. to get errors in english for forums):
LANG=C