bash how to echo quotes

Answer

In this case, it is essential to put a backslash. Backslash will focus on character followed by a sign with a backslash. The following characters depose functions of the meta tag.

If you want to echo single quotes, you can to:

echo Single quote: \'

Output: Single quote: '

If you want to to echo double quote, you can do:

echo Double quote: \"

Output: Double quote: "

If you want to quote single quote in double quotes:

echo "Single quote in double quotes: '"

Output: Single quote in double quotes: '

If you want to quotes double quotes in double quotes:

echo "Double quote in double quotes \""

Output: Double quote in double quotes "

There is 2 kinds of quoting: weak (") and strong ('). Using weak quoting there is no special meanings of:

  • pathname expansion
  • process substitution
  • single-quotes
  • characters for pattern matching
If we use strong quoting, nothing is interpreted, except single quote. Examples:

echo  "Path to your shell is: $SHELL"
echo 'Path to your shell is: $SHELL'

Output: Path to your shell is: /bin/bash
Path to your shell is: $SHELL

Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.