问题
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