Mihai Galos
Mihai Galos

Reputation: 1897

Echo bash variable in separate bash process

I'm trying to create a separate bash process and echo a variable which is set inside of it with no success. Nothing gets echoed.

bash -c "COMMIT_DIFF_FILE=diffs.diff && echo -e ${COMMIT_DIFF_FILE}"

What could be the problem here? Many thanks in advance!

Upvotes: 1

Views: 61

Answers (1)

anubhava
anubhava

Reputation: 785581

You have to quote it right.

bash -c 'COMMIT_DIFF_FILE="diffs.diff" && echo "$COMMIT_DIFF_FILE"'

diffs.diff

You are quoting command to bash -c in double quotes which gets expanded in current shell where variable is not present.

If you want to use double quotes then escape $:

bash -c "COMMIT_DIFF_FILE=diffs.diff && echo \${COMMIT_DIFF_FILE}"

Upvotes: 1

Related Questions