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

Question on unintuitive behaviour for function execution and parameter assignment



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