Article View: gnu.bash.bug
Article #986Re: can't unalias
From: Chet Ramey
Date: Thu, 21 Jan 1993 23:20
Date: Thu, 21 Jan 1993 23:20
50 lines
2250 bytes
2250 bytes
> I pared my personal startup file down to
>
> if [ "$PS1" ]; then :
> alias
> echo ====
> unalias ls
> alias
> ls () { /usr/bin/ls -aCFq "$@"; }
> fi
>
> which fails as previously described, no output from the alias command,
> just:
>
> bash$ bash
> syntax error near `()'
> /home/alpha/ruck/.shrc+:6: `ls () { /usr/bin/ls -aCFq "$@"; }'
> bash$
>
> BUT when I pull that block out of the if-then by commenting out the
> first and last line, I get it working fine.
>
There is alias expansion being performed, regardless of the presence of
the `alias' and `unalias' commands. Bash always reads a complete command,
which may consist of multiple lines, before executing it. In your case,
the `if...fi' block is a complete command, and bash is attempting to read
all of it and construct a command tree before executing the test or the
body.
Since alias expansion is performed when a command is read, the `ls' in
the above command is being expanded. You need to put `unalias ls'
before the if statement in which your function is defined. It won't
hurt to make the unalias unconditional; alias expansion is not performed
when the shell is not interactive.
> OR if I leave it in the if-then as shown above, and simply insert
> "function" in front of the function def, like
>
> function ls () { /usr/bin/ls -aCFq "$@"; }
This works because the `ls' is no longer the first word in a simple
command and therefore not eligible for alias expansion.
Chet
--
``The use of history as therapy means the corruption of history as history.''
-- Arthur Schlesinger
Chet Ramey, Case Western Reserve University Internet: chet@po.CWRU.Edu
Technical Details
Message-ID:
<9301211906.AA00764.SM@odin.INS.CWRU.Edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!odin.ins.cwru.edu!chetReferences:
<9301211836.AA20032@delta.ee.ufl.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!odin.ins.cwru.edu!chet From: chet@odin.ins.cwru.edu (Chet Ramey) Newsgroups: gnu.bash.bug Subject: Re: can't unalias Date: 21 Jan 1993 18:20:29 -0500 Organization: GNUs Not Usenet Lines: 51 Sender: daemon@cis.ohio-state.edu Approved: bug-bash@prep.ai.mit.edu Distribution: gnu Message-ID: <9301211906.AA00764.SM@odin.INS.CWRU.Edu> References: <9301211836.AA20032@delta.ee.ufl.edu> Reply-To: chet@po.cwru.edu