0

I have seen below two lines in a shell script. Im new to unix scripting, what is the use of setting this?

PATH=$PATH:/bin:/usr/bin:/usr/sbin:/sbin:/etc:/usr/ucb:/usr/ccs/bin:/usr/local/bin export PATH

Thanks in advance

John
  • 2,035
  • 13
  • 35
  • 44
  • possible duplicate of [bash: defining a variable with or without export](http://stackoverflow.com/questions/1158091/bash-defining-a-variable-with-or-without-export) – Shalom Craimer Dec 14 '11 at 07:22

2 Answers2

0

If you export something (in bash anyway which I assume is your shell), it will mark that something to be available in subsequently executed commands.

$ FOO=1 # Set the variable
$ echo $FOO # Check the value
1
$ bash # New shell here. 

$ echo $FOO # No value since it's not exported

$ exit # Quit the subshell
$ export FOO # Export it
$ bash
$ echo $FOO # It has a value now
1

export is a shell builtin for bash so doing a help export will give you more information on it.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • The example is good, but "subsequently executed commands" is the wrong phrase to use (a second `echo $FOO` command in the same shell would work just as well). You should use "shells" or "environments", or just elabotate a bit more. – itsadok Dec 14 '11 at 07:22
0

Explicitly exporting the PATH doesn't hurt but generally has no effect as the PATH variable is almost certainly already marked as exported when you launch a shell script.

jlliagre
  • 29,783
  • 6
  • 61
  • 72