如何领先的美元符号的影响在bash单引号? [英] how does the leading dollar sign affect single quotes in bash?

查看:224
本文介绍了如何领先的美元符号的影响在bash单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个字符串传递给一个程序从bash的CLI它的参数,例如

I need to pass a string to a program as its argument from the bash cli, e.g

program "don't do this"

该字符串可能包括诸如$,任何字符\\,等等,我不想BASH做任何修改。因此,我认为有关使用单引号。

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.

但下面不工作:

 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

第一种方法似乎是它获得较少pre修改(把美元符号在前面,并替换每个 \\ \\更好\\ ),但我不知道还有什么美元符号可能会做。

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.

我真的GOOGLE了这一点,但我无法找到我需要..先谢谢了。

I've really googled this but i can't find what i need.. Thanks in advance.

推荐答案

它会导致转义序列是间preTED。

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)

这篇关于如何领先的美元符号的影响在bash单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆