how to echo text containing with double quotes [duplicate]

孤街浪徒 提交于 2021-02-10 12:47:29

问题


I need to echo some text. like text "hey"

If i try with code echo "text "hey"" getting output as text hey

So, how to display the double quotes also. Can anyone help me with this.


回答1:


You can use

echo 'text "hey"'

or

echo "text \"hey\""

In short:

  • The double quote ( "quote" ) protects everything enclosed between two double quote marks except $, ', " and \. Use the double quotes when you want only variables and command substitution

    • Variable - Yes
    • Wildcards - No
    • Command substitution - yes
  • The single quote ( 'quote' ) protects everything enclosed between two single quote marks. It is used to turn off the special meaning of all characters.

    • Variable - No
    • Wildcards - No
    • Command substitution - No

Further details: https://bash.cyberciti.biz/guide/Quoting



来源:https://stackoverflow.com/questions/65154428/how-to-echo-text-containing-with-double-quotes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!