Karoline
Karoline

Reputation: 9

Make variables exist outside a shell script

I'm trying to make variables exits outside of a shell script without using source. The variables are declared in shell script with

export varA=3

and I run the script with ./filename.sh

I want

echo $varA

in the terminal to return 3 (i.e. the value of varA). So extend the scope of the variable to outside of the script

To sum up: how do I make the variables inside a shell script exist outside.

Thank you in advance

Upvotes: 0

Views: 1763

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7225

You can run your script on this way:

. ./filename.sh

This mean when run it will not spawn new shell but run it in current. And variables you set in your script will be available in your shell. This is kind of "source" as mentioned in comments.

Upvotes: 2

Related Questions