(list) # in sub-shell { list; } # in current shell
{ read first; read second; } <file tar cf - dir | (cd /tmp; tar xf -)
error() { echo "$0[error]: $@"; exit 1; } >&2 warn() { echo "$0[warn]: $@"; } >&2 info() { ((VERBOSE)) && echo "$0[info]: $@"; } >&2
debug() { local var quoted for var do quoted=${!var//\'/\'\\\'\'} info "$var='$quoted'" done }
return [n]
exit [n]
f() { trap date RETURN sleep 5 }
alias ls='ls --color=auto' alias ll='ls -l' ls() { command ls --color=auto "$@"; } ll() { ls -l "$@"; }
cd() { echo "OLD: $OLDPWD" builtin cd "$@" E=$? echo "NEW: $PWD" return $E }
f() { local i for i do echo "$0:$i done } f "$@"
get_id() ( set -o pipefail getent passwd "$1" \ | cut -d: -f3 ) uid=$(get_id user) found=$?
list() { eval ' for i in "${!'$1'[@]}" do printf -- "[%s] -> %s\n" \ "$i" "${'$1'["$i"]}" done' } declare -A a=([1st]=foo [2nd]=bar) list a
array_cp() { declare -gA "$2=()" declare -n from=$1 to=$2 local i for i in "${!from[@]}" do to[$i]=${from[$i]} done } declare -A a=([1st]=foo [2nd]=bar) array_cp a b
inc() { declare -n var=$1 R=BASH_REMATCH [[ $var =~ (.*)_([0-9]+)\.(.*) ]] \ && printf -- '%s_%03d.%s' \ "${R[1]}" \ $((10#${R[2]}+1)) \ "${R[3]}" } file=/var/tmp/backup_data_021.tgz inc file
# DEBUG / RETURN set -o functrace declare -tf f_name # ERR set -o errtrace FUNCNEST=0 export -f f_name