15
Condor
3y

'"I\ absolutely\ love\ bash\n"'
And somehow it will still be fucked up.

Comments
  • 10
    Why the escaped whitespaces in a quoted string? :)
  • 0
    Idk man, I'd do it like this?
    "I absolutely love bash"$'\n'
  • 2
    There's some pain involved but it's oddly satisfying. Bash is kinky.
  • 1
    @netikras it particularly becomes an issue when you try to parse stuff over SSH. With that you need 2 layers of escaping, or as many SSH consecutive connections as you need to make. Another issue is that the remote server might be running a different shell.
  • 1
    @Condor so then escape the quotes :)

    "\"this is some string\""

    Or even better -- wrap the top-level string in single quotes and get rid of those escapes:

    '"this is some string"'

    This way top-level command will take the doubly-quoted string as an argument (incl the double quotes) and send it to the remote machine.

    Escaping all the whitespaces feels... tedious :)
  • 1
    @netikras could work yeah, but the problem with single quotes is that you can't use variables in them.. and escaped double quotes would work too. But of course in the rant I kinda overexaggerated :P
  • 1
    @Condor I see :)

    Also, there's a 3rd option I have used a few times -- store that string in a variable generated with heredocs. A less portable, but highly flexible approach. This way you can have multiline text, variables and whatnot in the string. And pass it over to the command with a simple "${my_variable}" ;)
Add Comment