# ############################################################################ # Returns the N'th argument in a b c ... # Use: # arg N a b c d e # More typically: # arg 3 "$@" arg() { shift $1 echo "$1" } # ############################################################################ # # Returns path to a command, or "". # # Example: # If we have VNC server on this host, start one in the background: # VNCSERVER=`findcommand vncserver` # test "$VNCSERVER" != "" && vncserver ... # findcommand() { type "$1" 2>/dev/null | awk '$2 != "not" {print $NF}' } # ############################################################################ # # Sets status to 0/1 if value is true/false. # # Example: # echo -n "Proceed (y/n)? " # read ans # if [ testbool "$ans" ] ; then # ... # fi # testbool() { case "$1" in [Yy][Ee][Ss] | [Yy] | 1 | [Oo][Nn] | [Tt] | [Tt][Rr][Uu][Ee] ) true ;; * ) false ;; esac } # ############################################################################ # # Joins all args with colons and returns same. # # This is helpful when you want to construct a long path in a manner # that is easy to read and edit. # # Example: # path="a b c d ... # e f g h ... # x y z" # path=`colonjoin $path` # colonjoin() { path="$1" shift for p in "$@" ; do path=${path}:$p ; done echo $path } # ############################################################################