date and time created 88/07/21 17:32:12 by marc
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:32:12 +0000 (00:32 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:32:12 +0000 (00:32 -0800)
SCCS-vsn: local/toolchest/ksh/substring 1.1

usr/src/local/toolchest/ksh/substring [new file with mode: 0644]

diff --git a/usr/src/local/toolchest/ksh/substring b/usr/src/local/toolchest/ksh/substring
new file mode 100644 (file)
index 0000000..21825d4
--- /dev/null
@@ -0,0 +1,31 @@
+# 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
+}