Passing KM variables with spaces and/or quotes to shell script action

You never want to do this.

Getting the right level of quoting for everything in a situation like this is virtually impossible.

OK, you are in trouble before you start then I suspect.

My ~/.zsh_history has multiline commands in it, for example a line is:

while [ $i -le 1000 -a $(($(echo $(/bin/ps -xp 19012|/usr/bin/wc -l)))) -gt 1 ]; do\

But that is part of more lines, so it would not be valid on its own.

But ignoring that, and assuming the history line has a valid command in it, then yes, writing it to a script file and executing the file would be the way to go - putting it in a variable will never work because the shell quoting and interpolation does not happen recursively.

2 Likes