Function spurs::util::escape_for_bash
source · Expand description
Given a string, encode all single quotes so that the whole string can be passed correctly as a single argument to a bash command.
This is useful for passing commands to bash -c
(e.g. through ssh).
For example, if I want to run the following command:
echo '$HELLOWORLD="hello world"' | grep "hello"
This function will output 'echo '"'"'$HELLOWORLD="hello world"'"'"' | grep "hello"'
.
So the following command can be executed over ssh:
bash -c 'echo '"'"'$HELLOWORLD="hello world"'"'"' | grep "hello"'