Hacker News new | past | comments | ask | show | jobs | submit login

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




There'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


Yes 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!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: