4 ms·
Looks like the article stops just short of an example that requires a nasty amount of escape sequences and single quotes. If I need to do anything more complex
by dfinninger 5y ago
Looks like the article stops just short of an example that requires a nasty amount of escape sequences and single quotes.
If I need to do anything more complex than what the author is discussing I just reach for Python’s shlex.quote() function. The output gets rather hard to follow, but the code is much simpler.
I had to set up a script that SSHes into a host, then starts a screen session, then does some grepping/filtering on the remote output. Shlex made it possible. I couldn’t have come up with the arcane quoting without entering the maw of insanity!
- dundarious 5y agoOther options that are perhaps faster to use on the fly, are bash/zsh's builtin printf and GNU's printf command, with the %q conversion specifier (modulo the newline/trailing space issue). > bash$ printf "%q " \"yo" dude"\', it\'s\ me'!' ; echo > \"yo\ dude\'\, it\'s\ me\! > $ command printf "%q " \"yo" dude"\', it\'s\ me'!' ; echo > \"yo\ dude\'\, it\'s\ me\!
- deleted 5y ago[deleted]