1

I have a requirement where I have to set environment variables calling a script file eg:set_env.sh. set_env.sh contains all the environment variables.

export SCRIPT_DIR=/e/scripts/
...

when I call the set_env.sh from my code the variables are available in that file itself. They are not available in file where I have called the script.

What should be done so that environment variables can be retained and can be used in file which calls set_env.sh.


Using . set_env.sh works - thanks.

Some related links with explanation:

1 Answer 1

4

You need to do

. set_env.sh

This runs set_env.sh in your current shell, rather than starting a new one.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that the shell searches for the file using the locations in $PATH, and also that the file to be 'dotted' ('sourced' is the alternative name since Bash - and C shell - use the command 'source' as an alternative to dot; the C shell only supports 'source', but Bash supports both) does not have to be executable; it is sufficient if it is readable.

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.