2

I have a bash script,

echo 'abcd'

in shell, I want to show ab'c'd and I have tried following approach but without success

echo 'ab\'c\'d'

I am asking is it possible to show single quote in single quoted text?

Richard
  • 14,642
  • 18
  • 56
  • 77

2 Answers2

8

From the bash manual section on Single Quotes:

A single quote may not occur between single quotes, even when preceded by a backslash.

You'll need to use double quotes instead. It's not pretty, but the following gives the output you are looking for:

echo 'ab'"'"'c'"'"'d'
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
0

A bash-specific feature, not part of POSIX, is a $'...'-quoted string:

echo $'ab\'c\'d'

Such a string behaves identically to a single-quoted string, but does allow for a selection of \-escaped characters (such as \n, \t, and yes, \').

chepner
  • 497,756
  • 71
  • 530
  • 681