Using zsh or bash, I want to run a script that may prompt the user for multiple commands and store them as a function, however I'm finding that eval "function $FNCNAME() {"
or echo "function $FNCNAME() {" | zsh -is
is not valid unless typed directly since the script will not wait for more input before either continuing to the next line or exiting.
How do I block the script process while accepting user input, and continue only when the user has concluded the function definition with a final (unquoted) }
?
Requirements are:
- The shells own context aware autocomplete functionality is active.
- The script should not immediately execute the deferred commands but should be able to call or print the definition of the new function
This question is limited to a general piping and interaction problem. I am not asking for:
- How to provide prewritten commands to a script in any way.
- How to provide "the best user experience" or how to improve it.
- Why I should not solve this problem and do something else instead.