LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   dot space dot (https://www.linuxquestions.org/questions/linux-newbie-8/dot-space-dot-483359/)

binary_0011 09-14-2006 03:22 AM

dot space dot
 
can someone tell me why do i have to specfic . ./setup.sh (notice the space) ?

wat does the "space" in between the dots mean?

Thanks.

berbae 09-14-2006 03:44 AM

The first '.' is the command 'source' to read and execute commands from the filename given as argument.
The second '.' is the current directory.
. ./setup.sh
is the same as
source ./setup.sh
or
source setup.sh (if the ./, the current directory, is in the PATH environnement variable).

binary_0011 09-14-2006 04:07 AM

lol, i still dont get it, cant we just enter ./setup.sh ? in wat kind of circumstance we need to enter 2 dots?

Thanks.

berbae 09-14-2006 04:25 AM

With the 'source' or '.' command the script need not be executable.
If you use ./setup.sh the file must be so (eg 'rwxr-xr-x' permissions).

binary_0011 09-14-2006 05:02 AM

alright , i got it.

thanks.

theYinYeti 09-14-2006 07:43 AM

But more importantly:
- If you use the "source" or "." keywork, the script is executed in the current environment, which means that changes to variables (eg: PATH) or other (eg: cd /some/directory/) are still valid.
- Else such changes are forgotten when execution is done.

Example:

Code:

(/home/yves)$ echo $PATH
/bin:/usr/bin:/usr/X11R6/bin
(/home/yves)$ cat test.sh
export PATH=/usr/local/bin:$PATH
cd /usr/local
echo $PATH
pwd
(/home/yves)$ ./test.sh
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
/usr/local
(/home/yves)$ echo $PATH
/bin:/usr/bin:/usr/X11R6/bin
(/home/yves)$ . ./test.sh
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
/usr/local
(/usr/local)$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin

Notice how things remain changed when the script is sourced.

Yves.


All times are GMT -5. The time now is 06:59 AM.