summaryrefslogtreecommitdiffstats
path: root/bin/sed
blob: 352a3ca6e8528f8ac46a392de8b66c482e03daaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
#
# Sed portability notes
# - SuSv3
#    - Only -e, -f, and -n are standard options
# - Linux
#    - -i argument is of the form -i[ext]
#    - extended regular expressions argument is -r
# - Mac OSX
#    - -i argument is of the form -i [ext]
#    - extended regular expressions argument is -E
#
# Here we support a limited subset of the available sed capabilities,
# ensuring that all those supported by this script can be utilized
# regardless of the current platform.
#
# We accept -n, -e, -f, and -i with no backup extension.  We support
# extended regular expressions using the -r argument.  Note that extended
# regular expressions support may not be retained, depending upon the
# capabilities of the other platforms we wish to support, and we may need
# to reimplement -i internally in this script on some platforms.


source $(dirname $0)/wrapper.sh

case `uname -s` in
    Darwin)
        inplace_arg="-i ''"
        extended_re_arg="-E"
        getopt_os="ir"
        ;;
    Linux)
        inplace_arg="-i"
        extended_re_arg="-r"
        getopt_os="ir"
        ;;
esac

saved=""
while getopts ne:f:$getopt_os opt; do
    case "$opt" in
        n)
            save "-$opt"
            ;;
        e|f)
            save "-$opt"
            save "$OPTARG"
            ;;
        i)
            saved="$saved $inplace_arg"
            ;;
        r)
            saved="$saved $extended_re_arg"
            ;;
        \?)
            exit 1
            ;;
    esac
done
shift $(($OPTIND - 1))
for arg; do
    save "$arg"
done

exec_real