Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Treating alias or function arguments literally



On Sep 15,  4:20pm, zv wrote:
} Subject: Re: Treating alias or function arguments literally
}
} I have already declared this function `noglob' & `nocorrect'

This doesn't mean what you think it means.

Placing "setopt noglob nocorrect" *inside* a function DOES NOT affect
how the arguments of that function are interpreted.  Globbing occurs
as part of command line parsing before the function even begins to
execute.

The point of

  alias calc='noglob calc'

is to tell the command line parser not to perform globbing on that
command line, which will then protect the arguments.

} (I just checked with an alias and that doesn't effect it either)

In fact in my own .zshrc I have (dating back years to before zsh
had floating-point math in $(( )) expressions):

  calc () {
    awk "BEGIN {print $*}" < /dev/null
  }
  alias calc='noglob calc'

And it works exacly as intended:

schaefer<501> calc 4*3
12
schaefer<502> calc 20*15/2
150
schaefer<503> 

So ... what alias are you using that doesn't work?  Note that you have
to assign the alias *after* defining the function, or weird things
will result (see the FAQ).



Messages sorted by: Reverse Date, Date, Thread, Author