Quotation marks cancelling out command in bash to pass to variable

This question already has an answer here:

  • How to escape single quotes within single quoted strings? 19 answers

  • 你遇到的问题是你的单引号是不正确的,它们应该是重音符,所以不是“而是”


    Check that your command string to isolate the IP address is contained in back quotes. The back quote ` is different than the single quote ' or double quote " (assuming the command line works for your OS). Thus:

    userip=`ifconfig | grep "inet addr:" | cut -d: -f2  |  awk '{print $1}'`
    

    The back quotes cause the command to be executed and the results returned. The backquote is below the tilda ~ on most keyboards. (not sure the back quote is appearing in my answer. Just getting used to Stack Exchange.)

    链接地址: http://www.djcxy.com/p/57144.html

    上一篇: 使用选项在shell脚本中打印单引号

    下一篇: 引号取消在bash中的命令以传递给变量