# substring function # this function should be equivalent to the substring built-in which was # eliminated after the 06/29/84 version function substring { typeset lpat flag str #local variables set -o noglob #no file name generation case $1 in -l|-L) flag=$1 lpat=$2 shift 2 ;; esac # test for too few or too many arguments if [ x"$1" = x -o $# -gt 2 ] then print -u2 'substring: bad argument count' return 1 fi str=$1 if [ x"$flag" = x-l ] #substring -l lpat then str=${str#$lpat} elif [ x"$flag" = x-L ] then str=${str##$lpat} #substring -L lpat fi if [ x"$2" != x ] then echo ${str%$2} else echo $str fi return 0 }