|
Code Fragment Collection
|
|
Notice: Undefined variable: code_id in /srv/www/htdocs/copymycode/codes.php on line 89
example
This function is useful to display and record the warning count.
You may later use the count as failure exit code.
function warning()
{
echo "$@" 1>&2
((WARNING_COUNT++))
}name=`basename $file_path $suffix` Creates temporary files and uses exit trap to delete it
tmpfile=`mktemp` # ... your code is here ... trap 'rm -f $tmpfile' EXIT show_help= show_version= option= param= while test $# -gt 0 ; do arg=`expr "x$1" : 'x[^=]*=\(.*\)'` case $1 in --help | -h | '-?' ) show_help=yes ;; --version | -v ) show_version=yes ;; --opt | --option | -o ) option=yes ;; --param | --param=* ) test -z "$arg" && shift && test $# -gt 0 && arg=$1 param=$arg ;; -*) echo invalid option: $1 && exit 1 ;; *) # process argument echo "argument: [$1]" ;; esac shift done echo "show_help [$show_help]" echo "show_version [$show_version]" echo "option [$option]" echo "param [$param]" print <<< HERE Text to be printed.. HERE; This function just prints the message and exists.
The general usage can be something like that:
do_some_thing || die "could not do it" function die()
{
echo "$@" 1>&2
exit 1
} |