Question

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?

Was it helpful?

Solution

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'

OTHER TIPS

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, \').

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top