[Top][All Lists]

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

Re: alias-if-unalias-defun syntax error

From: Chet Ramey
Subject: Re: alias-if-unalias-defun syntax error
Date: Fri, 17 May 2002 12:48:13 -0400

> Machine Type: alphaev5-dec-osf5.1
> Bash Version: 2.05
> Patch Level: 8
> Release Status: release
> Description:
>   A syntax error occurs when the following lines are input from
>   command line or with 'source':
>       alias gzip='command gzip -v'
>       alias mygzip='command gzip'
>       if true; then
>         unalias mygzip
>         mygzip() {
>           gzip "$@"
>         }
>       fi

Of course.  It really is a syntax error.  Remember that bash always reads
a complete command before executing it, and that aliases are expanded when
a command is read.  The `if true; ... ; fi' construct is a single command,
and bash reads the whole thing at once.  The `mygzip' alias is
expanded before the unalias is executed, which results in a syntax error.

>       # variation 3
>       unalias gzip
>       alias mygzip='gzip'
>       if true; then
>         unalias mygzip
>         mygzip() {
>           gzip "$@"
>         }
>       fi

This one defines a recursive function named `gzip', by the way.  If you
think about it for a minute, you'll see why.

As I said in my previous message, the next-to-last paragraph of the
ALIASES section of the man page has more information.


``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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