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:

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
sandeep
  • 11
  • 1
  • 2

1 Answers1

4

You need to do

. set_env.sh

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

Oleks
  • 31,955
  • 11
  • 77
  • 132
Kevin Beck
  • 2,394
  • 2
  • 15
  • 27
  • 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. – Jonathan Leffler Feb 23 '11 at 07:54