What is the difference between these two commands?
. filename # (A)
and
filename # (B)
And how is this command related?
./filename # (C)
Note: The # and the rest of the line after it are comments.
|
What is the difference between these two commands?
and
And how is this command related?
Note: The # and the rest of the line after it are comments. |
|||||
|
|
Command (A) is called sourcing the file which consists of shell commands. It may not be used for binary executables (see
Command (B) causes the shell to execute the file only if the execution bit is on for the rights of the user (see
Command (C) is essentially the same as command (B), but it specifies the current directory which is referred to as "." (just as the parent directory is referred to as "..". The PATH will not be searched to locate the file since a directory is specified. [*] A relative path is one that does not start with a slash (/). It specifies a location relative to the current directory. "this/is/a/subdir" exists as a directory path under the current one as does "./this/is/a/subdir" (which specifies the same directory). "../another/set/of/dirs" is a set of directories below the parent of the current one. |
|||||||||||||||
|
|
If you source a script with
or
means that the script runs in the current shell. If you run
It will run in a new shell and will not have access to variables set in the current shell that have not been exported into the environment with "export". |
|||
|
|
|
Using the Normal behavior when you execute a program or script is to instantiate a new shell and launch the process. (That's why scripts start with "Sourcing" the script is useful for loading environment variables specific to an application, typically a database or development environment. If you run multiple Oracle or other database instances, you may have a set of "source" or "environment" scripts for the production, dev, and QA environments. If you have a compile farm that targets multiple platforms (ie. producing Solaris binaries from a Linux farm), you may have these scripts to easy load the proper environment variables. |
|||
|
|
|
A. . filename Executes script file in current context. Mostly used to export variables from shell script to current running shell. So if export some new variable in "~/.bash_profile" file and we want to apply changes in current shell without logging off, we can use command
to execute "~/.bash_profile" again in current context and get the new variables exported. B. filename If command is present in search path then it will get executed. File named command in current folder wont get executed, if current folder is not included in search path. To see current path use
If executable named "filename" is present in more than one folder in path. The executable in first listed folder in path will be executed. To see where is the file that is getting executed when to type "filename" use
C. ./filename It is used to execute filename named executable present in current working directory. |
|||||
|