3 ms·
Thanks! This bash string escape trick will be really useful for me(1). It is one of the biggest pain points in using cli especially with nested commands like su
by superasn 5y ago
Thanks! This bash string escape trick will be really useful for me(1). It is one of the biggest pain points in using cli especially with nested commands like su -c where the actual command is supposed to go inside quotes and becomes hell to quote if it too has nested quotes inside it.
Oh how i wish that bash and every other language would support the Perl's brilliant `q()` and `qq()` for quoting strings. That simple fn really made life very easy and code cleaner.
(1) https://til.simonwillison.net/bash/escaping-a-string https://til.simonwillison.net/bash/escaping-a-string
- ydant 5y agoThere's an easier way to escape in bash (that I didn't know about for very many hours of frustration): $ echo $'foo"\'"bar' $"foo'\"'bar" foo"'"bar $foo'"'bar
- superasn 5y agoYes I learned the same too yesterday from Hacker news. What a coincidence! There was also a bashquote function which you can put in your .bashrc file but this approach really beats everything!