3

I typed () in Terminal and got a prompt:

function>

I can't find any zsh documentation about it (or if it is even related to zsh). I realized I can type any gibberish anygibberish() and also get the prompt. If you continue to type () at the function> prompt, the prompt grows:

function function function>

There are custom functions in my .zshrc file and this function> prompt will execute those as if I was at a standard prompt.

function> config

Built-in functions work at the prompt as well:

function> ls -a

What else can the function> prompt do?

0

1 Answer 1

5

Zsh allows anonymous functions, which are executed right on the spot. For instance

() {
echo $1 $1 $1
} X Y

prints X X X. The main use in shell scripts is for having a piece of code where you want to define variables locally, without affecting the rest of your program. I don't see any pratical use for it in interactive shells, but if you do, the function prompt serves to remind you, that you are now inside a function definition.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .