I want to pass function arguments to zsh’s emulate to evaluate a command in bash emulation:

$ .bash() { emulate bash -c "$*" }
$ .bash 'source /path/to/script.sh'

It’s ok but I want this without quotes like a precommand modifier (to use syntax highlighting, completion, etc.) as in

$ .bash source /path/to/script.sh

The problem arises when a command line contains quoted spaces:

$ .bash source /path/to/"script with spaces".sh
$ # I want it to expand to
$ emulate bash -c 'source /path/to/"script with spaces".sh'
$ # or the like

I tried to play with different quotes and with ${(qq)*} expansion flags. No good so far.

Is there any way to achieve this?


You might have some success with

.bash() { emulate bash -c "$(echo ${(qq)@})" } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.