S. Y
S. Y

Reputation: 173

bash alias quotation mark escape

I am new here. I want to set up an alias in my .bashrc like the following:

alias printQt="echo ..." 

which prints the following:

X="a bcx "

However, it seems the nested quotation mark escaping is very hard to do. What do I need to write in place of the ... above?

Upvotes: 0

Views: 164

Answers (1)

Tom Fenech
Tom Fenech

Reputation: 74595

I guess that this is what you want:

$ alias printQt="echo 'X=\"a bcx \"'"
$ printQt 
X="a bcx "

Within double quotes, other double quotes need to be escaped. The single quotes go around the whole string that you want to echo.

Note that you can always just use a function instead:

printQt() { echo 'X="a bcx "'; }

Now the code is no longer a string, so things are a bit simpler.

Upvotes: 3

Related Questions