[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

aliasing "sed" to "sed --posix"

From: Bruce Korb
Subject: aliasing "sed" to "sed --posix"
Date: Sun, 05 Aug 2007 11:59:31 -0700
User-agent: Thunderbird (X11/20060911)

gnulib-tool has this entry:

# When using GNU sed, turn off as many GNU extensions as possible,
# to minimize the risk of accidentally using non-portable features.
# However, do this only for gnulib-tool itself, not for the code that
# gnulib-tool generates, since we don't want "sed --posix" to leak
# into makefiles.
if (alias) > /dev/null 2>&1 && echo | sed --posix -e d >/dev/null 2>&1; then
  alias sed='sed --posix'

Unfortunately, it does not work in bash by default.  Aliases are turned off.
Below is an experiment.  Invoke with and without an argument.  The results
look like this:

$ ./test.sh  xxx
aliasing supported
aliasing works in scripts 1
$ ./test.sh
aliasing supported
$ echo $?
$ cat test.sh
#! /bin/bash

(alias >/dev/null) && echo aliasing supported || exit 1

if test $# -gt 0
  can_alias=$(shopt 2>/dev/null | sed -n $'s/expand_aliases[ \t]*//p')
  case "${can_alias}" in
  off ) shopt -s expand_aliases ;;

alias exit='echo aliasing works in scripts'
exit 1
unalias exit
exit 0
echo woops
exit 1

reply via email to

[Prev in Thread] Current Thread [Next in Thread]