Yogesh
Yogesh

Reputation: 57

Single Quotations within a string in shell script

I have a requirement to embed single quotes in a string. How can I achieve via shell scripting?

Sample Input: --connect jdbc:sqlserver://XXXX:12;DatabaseName=S

Output: --connect 'jdbc:sqlserver://XXXX:12;DatabaseName=S'

The format of this will always remain same.

Upvotes: 0

Views: 55

Answers (2)

Gautam
Gautam

Reputation: 1932

You can use the following :

echo "--connect jdbc:sqlserver://XXXX:12;DatabaseName=S" | sed "s| jdbc| 'jdbc|g;s|$|'|g"

Upvotes: 1

nullPointer
nullPointer

Reputation: 4574

you could also escape them :

var=\'hello\'
echo $var

Outputs 'hello'

Upvotes: 0

Related Questions