I just need to pass any HTML content as a command line argument which includes characters like ', " , ` and what not? How can I pass this as a single argument in unix?
If you were typing at the command line, you could use the following hack:
some_program -some_option some_argument "$(cat)"
any text you like with ` or " or $ or < or whatever
^D
The last thing is control-D (end of file)
To put that into a bash script, you can use a Here document:
some_program -some_option some_argument "$(cat <<'EOF'
any text you like with ` or " or $ or < or whatever
EOF
)"
That will work as long as the text is not exactly the characters EOF (and if it is, you just have to change EOF in both places to something else).
But I don't think either of those are what you want to do. I think you are trying to invoke a program from another program (in Lua). Unfortunately, Lua out-of-the-box does not provide any function which can do that. It only provides os.execute, which uses the shell (/bin/sh, not bash) to interpret the command line.
There was a nice implementation for Lua of spawn
written by Mark Edgar, but I don't know if it is still maintained. Failing that, you can still use the second hack:
require("os")
function call_with_arg(prog, rawtext)
return os.execute(prog.." \"$(cat <<'EOF'\n"..rawtext.."\nEOF\n)\"")
end
local html =
[=[<html><body><img src="image.png" onload='alert("loaded")'/></body></html>]=]
call_with_arg("echo >somefile.txt", html)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With