Skip to content

Commit 3f8f0fa

Browse files
committed
l: use more portable grep invocations
Following on from commit b91bdf3 which used egrep and fgrep for better portability. Since GNU grep from v3.8 is warning about uses of [ef]grep instead just replace fgrep with grep, and egrep with {/usr/xpg4/bin/,}grep -E.
1 parent 76202ee commit 3f8f0fa

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • scripts

scripts/l

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
# apply thousands separator to file sizes
2121
BLOCK_SIZE=\'1; export BLOCK_SIZE
2222

23+
# Get access to grep that supports POSIX -E option on Solaris.
24+
# Note we don't just add /usr/xpg4/bin to PATH as that has
25+
# an incompatible sed.
26+
if echo . | /usr/xpg4/bin/grep -E -q . 2>/dev/null; then
27+
egrep='/usr/xpg4/bin/grep -E'
28+
else
29+
egrep='grep -E'
30+
fi
31+
2332
# Traditional unix time format with abbreviated month translated from locale.
2433
# en_* locales default to ISO format without this for reasons discussed here:
2534
# http://lists.gnu.org/archive/html/bug-coreutils/2009-09/msg00433.html
@@ -42,7 +51,8 @@ ESC=`printf '\033'`
4251
if ! tput setaf 1 >/dev/null 2>&1 && ! tput AF 1 >/dev/null 2>&1; then
4352
color_when=
4453
# enable highlighting if outputting to terminal or forcing
45-
elif test -t 1 || echo "$*" | egrep -- "--color( |=always|$)" >/dev/null; then
54+
elif test -t 1 \
55+
|| echo "$*" | $egrep -- "--color( |=always|$)" >/dev/null; then
4656
# Note if the user specifies --color=auto then that will override this
4757
# and hence the output will not be colored :(
4858
color_when=always
@@ -101,9 +111,9 @@ if [ "$color_when" ]; then
101111

102112
# Newer ls use "mh" to represent the color for multi hardlinked
103113
# files so handle the backwards incompatibility with "hl"
104-
if dircolors | fgrep ":mh=" >/dev/null; then
114+
if dircolors | grep ":mh=" >/dev/null; then
105115
hl_no_color="s/:hl=[^:]*:/:mh=:/; s/:mh=[^:]*:/:mh=:/"
106-
elif dircolors | fgrep "hl=" >/dev/null; then
116+
elif dircolors | grep ":hl=" >/dev/null; then
107117
hl_no_color="s/:mh=[^:]*:/:hl=:/; s/:hl=[^:]*:/:hl=:/"
108118
fi
109119

0 commit comments

Comments
 (0)