search

Home  >  Q&A  >  body text

为什么linux PS1变量的内容用单引号而非双引号围起来?

书上说单引号表示原字符,而双引号能表示出内在含义.那为何linux中PS1变量用单引号围起来却能表达出内在含义?
比如这样:

[root]#set |grep PS1
PS1='[\u]\$'
[root]#

百度也查到了同样的问题,但明显没回答好

PHPzPHPz2857 days ago748

reply all(3)I'll reply

  • PHPz

    PHPz2017-04-17 12:10:17

    The value of PS1 here is [u]$. The reason why it is finally displayed as [root]# is entirely because bash has done another explanation operation!
    Because bash needs to explain how to display it after seeing [u]$. According to bash rules, u is to display the login account name. $You can search it yourself.

    reply
    0
  • 迷茫

    迷茫2017-04-17 12:10:17

    Single quotes are not escaped, double quotes are escaped, for example, a='123', then
    echo ‘a$a’
    The output is a$a
    echo “a$a”
    The output is a123

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 12:10:17

    Has your file been resolved? I have the same problem and I couldn’t find the answer online

    reply
    0
  • Cancelreply