Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escaping quotes in environment variable within a shell

I'm trying to use quotes while defining an environment variable.

For example:

setenv SOME_TEMP_ENV "-arg "hello world""

Although Its fails with the following error:

setenv: Too many arguments.

After reading some therds about escaping quotes, I tried the following:

setenv SOME_TEMP_ENV "-arg \"hello world\""
setenv SOME_TEMP_ENV "-arg '"'"'hello world'"'"'"

Also, I could use the following method:

setenv SOME_TEMP_ENV "-arg "'"hello world"'""

But it doesn't fulfill my requirements:

echo $SOME_TEMP_ENV
-arg 'hello world' // should be -arg "hello world"

How can I use quotes in an environment variable?

** EDIT **: I have to use the double quotes around the string because my script for some reason can't read the string is its looks like this: '-arg "hello world"'

like image 914
TTaJTa4 Avatar asked Jul 11 '26 03:07

TTaJTa4


2 Answers

Use single quotes around the string.

setenv SOME_TEMP_ENV '-arg "hello world"'
like image 110
Barmar Avatar answered Jul 14 '26 04:07

Barmar


Using single quotes as the outside wrapper will work in both csh (which your question appears to be about) and bash (which your question was tagged as):

'-arg "hello world"'
like image 40
Ollin Boer Bohan Avatar answered Jul 14 '26 04:07

Ollin Boer Bohan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!