2 # Chet Ramey <chet.ramey@case.edu>
4 # Copyright 2002 Chester Ramey
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # TThis program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # substr -- a function to emulate the ancient ksh builtin
24 # -l == shortest from left
25 # -L == longest from left
26 # -r == shortest from right (the default)
27 # -R == longest from right
32 local usage="usage: substr -lLrR pat string or substr string pat"
41 echo "substr: unknown option: $1"
51 if [ "$#" -eq 0 ] || [ "$#" -gt 2 ] ; then
52 echo "substr: bad argument count"
59 # We don't want -f, but we don't want to turn it back on if
60 # we didn't have it already
73 str="${str#$pat}" # substr -l pat string
76 str="${str##$pat}" # substr -L pat string
79 str="${str%$pat}" # substr -r pat string
82 str="${str%%$pat}" # substr -R pat string
85 str="${str%$2}" # substr string pat
92 # If we had file name generation when we started, re-enable it
94 if [ "$fng" = "1" ] ; then