Please excuse me if I am not clear while asking questions. I will try my best to be very clear while asking questions.

While learning Embedded Linux, we are setting an environment for our project. We wrote a shell script to set the environment which is similar to this:

export PROJECT=example-sys
export PRJROOT=/home/karim/${PROJECT}
export TARGET=powerpc-linux
export PREFIX=${PRJROOT}/tools
export PATH=${PREFIX}/bin:${PATH}

Saved the script as prjenv.sh. As I practiced running the scripts or any executable using ./xyz.sh or ./abc, I ran ./prjenv.sh and the shell did not complain but when I gave export -p to see if the variables were exported or not, I could not find them in the list.

Later I noticed, I was expected to use . prjenv.sh, after I ran the script, it set the environment variables.

May I know what is the difference between . and ./ and when to use which one?

Please let me know if you need more information.

PS: This is my first time working with Linux so I apologize if some of the technical terms I used are wrong.


1 Answer 1


./script will run the file script located in the current directory . as a new process.

. script calls the shell function . (which is an alias to source) with the argument script. This is pretty much the same as entering all the contained lines in the current shell.

You cannot set variables using the first option as the variables are set only for the new process. Variables are only exported from parent to child not the other way around. (i.e. a called process cannot modify variables in the current process.)

  • Thank you for your quick reply. Its really helpful. One more quick question. Does it mean after running the script using "./script" if we close the parent process, those variables will be available after reopening another process? or it means Variables exported in child process are never available after child process is done executing the script? May 19, 2014 at 1:22
  • A process is something running in memory in its own little world. On termination this whole world/memory is deleted, including all of the variables set into this world. - There are no global/persistent variables. If you need something like this you usually put them in some startup file like ~/.bashrc. In this case whenever a new bash is started it reads that file and sets the variables it its own world. If the variables are exported, those variables are available to any child, i.e. any command started by this shell.
    – michas
    May 19, 2014 at 5:13

Not the answer you're looking for? Browse other questions tagged .