how to echo text containing with double quotes

Viewed 4610

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 Answers

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

Related