Command to escape a string in bash
Pure Bash, use parameter substitution:
string="Hello\ world"
echo ${string//\\/\\\\} | someprog
In Bash:
printf "%q" "hello\world" | someprog
for example:
printf "%q" "hello\world"
hello\\world
This could be used through variables too:
printf -v var "%q\n" "hello\world"
echo "$var"
hello\\world