Thida
Thida

Reputation: 59

shell script reading variables from a shell script

How to take the variable like this?

a.sh

#!/bin/sh
./b.sh
echo "The message is: $MESSAGE"

b.sh

#!/bin/sh
MESSAGE="hello"

Then run:

$ ./a.sh
The message is:

I want to take the value of variable MESSAGE in a.sh

How can I do?

Upvotes: 0

Views: 48

Answers (1)

John3136
John3136

Reputation: 29266

If you do . ./b.sh (or source b.sh depending on your shell flavor) it will run b in the same shell as a rather than starting a different process.

Upvotes: 1

Related Questions