How does the first dollar sign affect simple quotes in bash?
source link: https://www.codesd.com/item/how-does-the-first-dollar-sign-affect-simple-quotes-in-bash.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How does the first dollar sign affect simple quotes in bash?
I need to pass a string to a program as its argument from the bash cli, e.g
program "don't do this"
The string may include any character like '$', '\', etc. and i don't want BASH to do any modification. So i think about using single quotes.
However the following does not work:
program 'don\'t do this' //escape doesn't work in single quote
While the following two works:
program $'dont\'t do this' //seems fine, but any other side effects?
program 'dont'\''do this' //breaking into 3 parts
The first approach seems better in that it acquires less pre modification (put the dollar symbol in front and substitute every \
to \\
), but i don't know what else the DOLLAR SIGN might do.
I've really googled this but i can't find what i need.. Thanks in advance.
It causes escape sequences to be interpreted.
$ echo $'Name\tAge\nBob\t24\nMary\t36'
Name Age
Bob 24
Mary 36
(And SO handles tabs in a goofy manner, so try this one at home)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK