1

I can do

bash -x mysellh.sh

to see the commands as they are being executed, but I don't see the variables replaced with their values. For instance, if I have in the shell script:

screen -d -m sh -c 'RAILS_ENV="$R_ENV" bundle exec rake sunspot:solr:reindex[500] > "$PROJECT_DIR"/solr/indexing_out.txt'

I will see:

+ screen -d -m sh -c 'RAILS_ENV="$R_ENV" bundle exec rake sunspot:solr:reindex[500] > "$PROJECT_DIR"/solr/indexing_out.txt'

Even though I've already declared earlier:

R_ENV=test

Is there an option to do what I want?

EastsideDev
  • 6,257
  • 9
  • 59
  • 116
  • 1
    See: [Difference between single and double quotes in bash](http://stackoverflow.com/q/6697753/3776858) – Cyrus Apr 21 '16 at 19:18

1 Answers1

3

In this case, it is doing what you asked: the command line "word" that $R_ENV is in is what you have enclosed in single quotes, which inhibit expansion. The -x output is showing you the non-expansion. If you want those variables to be expanded, enclose that first "word" in double quotes and use single quotes in the contents, like this:

screen -d -m sh -c "RAILS_ENV='$R_ENV' bundle exec rake sunspot:solr:reindex[500] > '$PROJECT_DIR'/solr/indexing_out.txt"

Then the single quotes are around the expanded text and the double quotes allow the variables to expand.

Greg Tarsa
  • 1,622
  • 13
  • 18