2

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?

  • 1
    Is there a reason to not use source myFile command to "source" the file? – ssssteffff Apr 26 '14 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 '14 at 9:15
3

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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