3 ms·
I learned recently that escaping characters in zsh/bash also works for parameter expansion: # zsh using flags ${(flags)name} % string="This is a string wit
by yonrg 6y ago
I learned recently that escaping characters in zsh/bash also works for parameter expansion:
# zsh using flags ${(flags)name}
% string="This is a string with \"\"\" and ''' and \"\" again ''. Also such stuff as & % # ;"
% echo $string
This is a string with """ and ''' and "" again ''. Also such stuff as & % # ;
% echo ${(q)string}
This\ is\ a\ string\ with\ \"\"\"\ and\ \'\'\'\ and\ \"\"\ again\ \'\'.\ Also\ such\ stuff\ as\ \&\ %\ \#\ \;
# bash using operators ${name@operator}
% string="This is a string with \"\"\" and ''' and \"\" again ''. Also such stuff as & % # ;"
% echo $string
This is a string with """ and ''' and "" again ''. Also such stuff as & % # ;
% echo ${string@Q}
'This is a string with """ and '\'''\'''\'' and "" again '\'''\''. Also such stuff as & % # ;'
Wow, so easy then, I remember struggling so many times in the past when e.g. iterating over filenames with unusual cahracters.
/edit: fix markup
- deleted 6y ago[deleted]