zsh-users
 help / color / mirror / code / Atom feed
* Treating alias or function arguments literally
@ 2016-09-15 21:47 zv
  2016-09-15 22:48 ` Jérémie Roquet
  0 siblings, 1 reply; 4+ messages in thread
From: zv @ 2016-09-15 21:47 UTC (permalink / raw)
  To: zsh-users

I have a calculator function that I use from ZSH directly which frequently triggers shell expansion, e.g

	[zv@syszv] ~/zv.github.com [master*] >> calc 20*15/2
	zsh: no matches found: 20*15/2

Is there any way I can ask zsh to supply a particular alias or functions parameters either without expansion or as a single string?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Treating alias or function arguments literally
  2016-09-15 21:47 Treating alias or function arguments literally zv
@ 2016-09-15 22:48 ` Jérémie Roquet
  2016-09-15 23:20   ` zv
  0 siblings, 1 reply; 4+ messages in thread
From: Jérémie Roquet @ 2016-09-15 22:48 UTC (permalink / raw)
  To: zv; +Cc: Zsh Users

Hi,

2016-09-15 23:47 GMT+02:00 zv <zv@nxvr.org>:
> I have a calculator function that I use from ZSH directly which frequently triggers shell expansion, e.g
>
>         [zv@syszv] ~/zv.github.com [master*] >> calc 20*15/2
>         zsh: no matches found: 20*15/2
>
> Is there any way I can ask zsh to supply a particular alias or functions parameters either without expansion or as a single string?

Sure: alias calc='noglob calc'

Best regards,

-- 
Jérémie


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Treating alias or function arguments literally
  2016-09-15 22:48 ` Jérémie Roquet
@ 2016-09-15 23:20   ` zv
  2016-09-16  0:30     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: zv @ 2016-09-15 23:20 UTC (permalink / raw)
  To: Jérémie Roquet; +Cc: Zsh Users

I have already declared this function `noglob' & `nocorrect' (I just checked with an alias and that doesn't effect it either)



On 09/15/2016 03:48 PM, Jérémie Roquet wrote:
> Hi,
>
> 2016-09-15 23:47 GMT+02:00 zv <zv@nxvr.org>:
>> I have a calculator function that I use from ZSH directly which frequently triggers shell expansion, e.g
>>
>>         [zv@syszv] ~/zv.github.com [master*] >> calc 20*15/2
>>         zsh: no matches found: 20*15/2
>>
>> Is there any way I can ask zsh to supply a particular alias or functions parameters either without expansion or as a single string?
> Sure: alias calc='noglob calc'
>
> Best regards,
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Treating alias or function arguments literally
  2016-09-15 23:20   ` zv
@ 2016-09-16  0:30     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-09-16  0:30 UTC (permalink / raw)
  To: Zsh Users

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).


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-09-16  0:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-15 21:47 Treating alias or function arguments literally zv
2016-09-15 22:48 ` Jérémie Roquet
2016-09-15 23:20   ` zv
2016-09-16  0:30     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).