1

I need to take specific variables from one script and use them in a different script.

Example:

Original script:

VARA=4              # Some description of VARA
VARB=6              # Some description of VARB
SOMEOTHERVAR="Foo"
/call/to/some/program

I want to write a second script that needs VARA and VARB, but not SOMEOTHERVAR or the call to the program.

I can already do:

eval $(grep 'VARA=' origscript.sh)
eval $(grep 'VARB=' origscript.sh)

This seems to work, but when I want to do both, like this, it only sets the first:

eval $(grep 'VAR[AB]=' origscript.sh)

because it seems to concatenate the two lines that grep returns. (Which probably means that the comments save the first assignments.)

1 Answer 1

2

Put quotes around it, so that the newlines in the output of grep will not be turned into spaces.

eval "$(grep 'VAR[AB]=' origscript.sh)"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.