Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to load serveral variables from a file (not .bash_*) which has similar to:

export MY_VAR='foo'

The command I was using to "source" this was

`tail -1 myFile`

This works, but it I echo $MY_VAR, I get

'foo'

But it I actually run export MY_VAR='foo' in the terminal, then echo $MY_VAR it outputs:

foo

Why the descrepancy in the quotes and how do I fix this?

share|improve this question
1  
Is there a reason to not use source myFile command to "source" the file? –  ssssteffff Apr 26 at 9:11
    
It is the apache envvars file, I add a few envvars for my site, and need only those to be sourced when I log in over ssh. I am totally open to other strategies. –  Jacob Valenta Apr 26 at 9:15

1 Answer 1

up vote 3 down vote accepted

Using backticks is something that is referred to as command substitution. The shell substitutes it after parsing tokens in the output. Since it encountered quotes in the output, it'd escape those. As such, it'd execute:

export MY_VAR=\'foo\'

leaving the variable surrounded with quotes.

You could instead make use of process substitution and continue to use the source command:

source <(tail -1 myFile)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.