Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Question on unintuitive behaviour for function execution and parameter assignment
- X-seq: zsh-workers 49471
- From: Jett Husher <jetthusher@xxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Question on unintuitive behaviour for function execution and parameter assignment
- Date: Tue, 12 Oct 2021 08:20:00 +0000
- Archived-at: <https://zsh.org/workers/49471>
- List-id: <zsh-workers.zsh.org>
- Reply-to: Jett Husher <jetthusher@xxxxx>
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'?
```
POSIX spec says that parameter assignment with function execution will alter the current shell environment and that it's not specified what's going to happen with this parameter at the end of the execution. `zshmisc(1)` in FUNCTIONS states that functions are called on a parent process, so my intuition was that this sort of code should not work for them. Unfortunately, I could not find any more information about this in the manuals or FAQs.
Can manuals be updated to cover this behaviour, please?
Thank you for your time.
- Jett
Messages sorted by:
Reverse Date,
Date,
Thread,
Author