Commit | Line | Data |
---|---|---|
7ab642dc MT |
1 | # substring function |
2 | # this function should be equivalent to the substring built-in which was | |
3 | # eliminated after the 06/29/84 version | |
4 | function substring | |
5 | { | |
6 | typeset lpat flag str #local variables | |
7 | set -o noglob #no file name generation | |
8 | case $1 in | |
9 | -l|-L) | |
10 | flag=$1 | |
11 | lpat=$2 | |
12 | shift 2 | |
13 | ;; | |
14 | esac | |
15 | # test for too few or too many arguments | |
16 | if [ x"$1" = x -o $# -gt 2 ] | |
17 | then print -u2 'substring: bad argument count' | |
18 | return 1 | |
19 | fi | |
20 | str=$1 | |
21 | if [ x"$flag" = x-l ] #substring -l lpat | |
22 | then str=${str#$lpat} | |
23 | elif [ x"$flag" = x-L ] | |
24 | then str=${str##$lpat} #substring -L lpat | |
25 | fi | |
26 | if [ x"$2" != x ] | |
27 | then echo ${str%$2} | |
28 | else echo $str | |
29 | fi | |
30 | return 0 | |
31 | } |