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'
fi
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 $?
1
$ cat test.sh
#! /bin/bash
(alias >/dev/null) && echo aliasing supported || exit 1
if test $# -gt 0
then
can_alias=$(shopt 2>/dev/null | sed -n $'s/expand_aliases[ \t]*//p')
case "${can_alias}" in
off ) shopt -s expand_aliases ;;
esac
fi
alias exit='echo aliasing works in scripts'
exit 1
unalias exit
exit 0
echo woops
exit 1