Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Escaping strings in Bash using !#
TIL this trick, via Pascal Hirsch on Twitter. Enter a line of Bash starting with a # comment, then run !:q on the next line to see what that would be with proper Bash escaping applied.
1bash-3.2$ # This string 'has single' "and double" quotes and a $2bash-3.2$ !:q3'# This string '\''has single'\'' "and double" quotes and a $'4bash: # This string 'has single' "and double" quotes and a $: command not foundHow does this work? James Coglan explains:
The
!character begins a history expansion;!stringproduces the last command beginning withstring, and:qis a modifier that quotes the result; so I’m guessing this is equivalent to!stringwherestringis"", so it produces the most recent command, just like!!does
A bunch more useful tips in the thread about this on Hacker News.
Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.