[Top][All Lists]

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

Re: aliasing "sed" to "sed --posix"

From: Eric Blake
Subject: Re: aliasing "sed" to "sed --posix"
Date: Mon, 06 Aug 2007 06:17:42 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070728 Thunderbird/ Mnenhy/

Hash: SHA1

According to Bruno Haible on 8/6/2007 2:10 AM:
> Your experiment uses the 'exit' command to test whether aliases are supported.
> However, 'exit' is a shell built-in. Whereas 'sed' is not and will likely
> never be a shell built-in. Can you retry your experiment with a non-built-in?

According to POSIX, aliases are expanded after recognition of reserved
words in correct context (such as if) but prior to other grammatical rules
(ie. before the shell knows whether the word being expanded is a shell
builtin or not).  Therefore, making an alias for exit is legal.

> In gnulib-tool line 468 you see that the usual way to override built-ins in
> bash is to define them as a function, because 'alias' does not work for them.

According to POSIX, functions override normal builtins (such as test) but
not special builtins (such as exit).  But aliases are expanded prior to
the place where function existence is checked.  Your argument that alias
cannot override builtins is flawed; in fact, aliases are the ONLY way to
override special builtins.

In fact, some people use something similar to the following alias in
interactive settings in order to temporarily disable globbing, so they
don't have to type as many quote characters to protect file globs passed
to the find utility.  The alias intentionally changes the parse
environment prior to calling a helper function, and for this to work, it
has to be an alias, not a function, since globs are already expanded when
a function is called:

alias find='_find(){set +f;\find "$@";};set -f;_find'

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

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