Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Question on unintuitive behaviour for function execution and parameter assignment
- X-seq: zsh-workers 49472
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Jett Husher <jetthusher@xxxxx>, zsh-workers@xxxxxxx
- Subject: Re: Question on unintuitive behaviour for function execution and parameter assignment
- Date: Tue, 12 Oct 2021 09:31:25 +0100 (BST)
- Archived-at: <https://zsh.org/workers/49472>
- Importance: Medium
- In-reply-to: <78LG0jAMo3FtN941LSwAK1kIhfcF6dszDg8-71F1TxHB3vKubQBIIAWx8yujorTI1mEI8iq4Rsahakh7IfgcNXdq2KMviv805m0imzBh5Sk=@pm.me>
- List-id: <zsh-workers.zsh.org>
- References: <78LG0jAMo3FtN941LSwAK1kIhfcF6dszDg8-71F1TxHB3vKubQBIIAWx8yujorTI1mEI8iq4Rsahakh7IfgcNXdq2KMviv805m0imzBh5Sk=@pm.me>
> On 12 October 2021 at 09:20 Jett Husher <jetthusher@xxxxx> wrote:
>
>
> Good day!
>
> Does a function `assign-hello` treat parameter assignment on simple command as local parameter in the following code snipped?
>
> ```
> HELLO=WORLD
>
> function assign-hello() HELLO=$1
>
> assign-hello THERE
> echo $HELLO # Prints 'THERE', as expected
>
> # This part trips me up
> HELLO= assign-hello WHY
> echo $HELLO # Why does it still print 'THERE'?
> ```
This is covered by the POSIX_BUILTINS option. Generally, the POSIX_* options are
the place to look for this sort of think --- granted that can be a bit of hunt.
Usually an easy test to see if zsh does have the POSIX behaviour available is
to start a new shell as
ARGV0=sh zsh
and see what behaviour that gives you. That should be maximally compatible,
although it doesn't help you find which option controls the behaviour.
POSIX_BUILTINS <K> <S>
When this option is set the command builtin can be used to execute shell
builtin commands. Parameter assignments specified before shell functions
and special builtins are kept after the command completes unless the spe‐
cial builtin is prefixed with the command builtin. Special builtins are .,
:, break, continue, declare, eval, exit, export, integer, local, readonly,
return, set, shift, source, times, trap and unset.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author