5

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.

Spooky
  • 205
  • 1
  • 2
  • 7
  • 1
    Simply type `echo 'text "hey"'` - wrap the entire string in single quotes ('). Here's why: https://www.howtogeek.com/howto/29980/whats-the-difference-between-single-and-double-quotes-in-the-bash-shell/ – paulsm4 Dec 05 '20 at 06:32

1 Answers1

8

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

Picaud Vincent
  • 10,518
  • 5
  • 31
  • 70
  • Thanks for this. It confirmed I was going about it the correct way, and lead me to the ultimate solution to my issue, which I'll share here in the off chance that it may help another poor soul: The file I received had Windows-style line endings, which messed everything up (`^M`s will be visible if you open a file in vim). – J.M. Janzen Jan 13 '22 at 21:48