Dushistov / sdcv

https://dushistov.github.io/sdcv/
GNU General Public License v2.0
294 stars 42 forks source link

Use single quotes around JSON data to reduce need for escaping #37

Closed nijel closed 6 years ago

nijel commented 6 years ago

Also use unicode escape sequence for newline to avoid problems with some shells decoding \n even when they probably should not.

Frenzie commented 6 years ago

I'm not entirely sure that they shouldn't. When you use \\\n logically what you have is escaped \ plus meaningless \n triggering fallback behavior. That could cause issues while passing it down. Like I said, I assume the correct form is probably \\\\n.

nijel commented 6 years ago

While I agree with you, the sh implementation does not:

$ sh -c 'echo "\n"'

$ bash -c 'echo "\n"'
\n
$ sh -c 'echo "\\n"'

$ bash -c 'echo "\\n"'
\n
$ sh -c 'echo "\\\n"'
\n
$ bash -c 'echo "\\\n"'
\\n
$ sh -c 'echo "\\\\n"'
\n
$ bash -c 'echo "\\\\n"'
\\n
Frenzie commented 6 years ago

Afaik know in our Debian the sh implementation is provided by Dash (by default), which does indeed treat backslashes differently in echo.

$ dash -c 'echo "\\\\n"'
\n

That doesn't answer the question though. The same behavior shouldn't occur when not using echo. For example, when using the actually portable printf.

$ dash -c 'bla="\\\\n"; printf "%s" "$bla"'
\\n