Big Shield
Big Shield

Reputation: 622

Is there a way to assign a quoted string to a var without escaping?

I don't want to escape the single quote below:

a='I'm a $coder.'

Is there a trick to do that?

Upvotes: 1

Views: 72

Answers (4)

user8017719
user8017719

Reputation:

A two step solution:

$ b='$coder'
$ a="I'm a $b"

$ echo "$a"
I'm a $coder

Upvotes: 0

that other guy
that other guy

Reputation: 123570

You can avoid all forms of quoting and escaping using a here document:

IFS= read -rd '' a << "END"
I'm a $coder, hear me roar: ~!@#$%^&*()+"]',/
END

Upvotes: 4

Cyrus
Cyrus

Reputation: 88776

I suggest:

 a="I'm a "'$coder.'

Upvotes: 2

P.P
P.P

Reputation: 121407

You can use double quotes (without needing to escape):

a="'I'm a $coder.'"

Upvotes: 1

Related Questions