You are not logged in.

#1 2012-01-10 15:46:07

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

[Solved] bash: Print both single and double quotes in a variable

I have a variable that I'd like to assign that requires the string to be begin and end in both a single and double quote and I can't figure out how to do it.  I think because of "variable expansion (is it?)" that bash is negating it.  For example:

test='"string"'
echo $test
"string"

So obviously I try:

test=''"string"''
echo $test

Which is producing:

string

What I literally need the string to be is:

'"string"'

I haven't been able to find a way to do this.  I know that this is unique.  Does anyone know of a way to do this?

Last edited by Gen2ly (2012-01-10 18:30:30)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#2 2012-01-10 15:55:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [Solved] bash: Print both single and double quotes in a variable

test=\'\"string\"\'
echo $test
'"string"'

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-01-10 16:01:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [Solved] bash: Print both single and double quotes in a variable

Or if you want to risk going blind counting ticks

test="'"'"string"'"'"
echo $test
'"string"'

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2012-01-10 18:04:52

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] bash: Print both single and double quotes in a variable

ohh, should have figured.  Thanks for the help Trilby.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

Board footer

Powered by FluxBB