User Tools

Site Tools


bash_functions

This is an old revision of the document!


Bash Functions

index # Print the position of $2 in $1

index() #@ Print the position of $2 in $1
{ #@ USAGE: index STRING SUBSTRING
local idx
case $1 in
*$2*) idx=${1%%$2*}
echo $(( ${#idx} + 1 )) ;;
*) echo 0 ;;
esac
}

From Article

die #@ Exit with error code and optional message

die() #@ Exit with error code and optional message
{ #@ USAGE: die RETURN_CODE [MESSAGE]
result=$1
shift
[ -n "$*" ] && printf "%s\n" "$*" >&2
exit "$result"
}

From Article

bash_functions.1368036190.txt.gz · Last modified: 2020/08/10 02:28 (external edit)