What does it mean in Unix when you use . ./<filename>
?
Thanks开发者_如何学Go for the help
". ./?" would try and run a program called '?' which would reside in the current directory and it would be run in the current shell.
The first dot means 'run in current shell' (rather than spawning a new one)., the './' means 'current directory' and '?' would mean an executable file called '?' would have to exist.
Running .
on a filename runs the commands in the file as though you typed them at the shell command prompt. Unlike a shell script, environment variable (and similar) changes produced by the file persist beyond running the file; the changes made by a shell script are reverted when the script finishes.
The .
or source
command reads the given file into the current shell. I.e. basically the given file is a shellscript which is run by typing . filename
, however using .
(or source
, which is equivalent) differs from running the file ordinarily as a shell script in that it doesn't spawn a subshell and thus retains variables that are exported by the script. So if the script sets and exports variables, they will still be set when the script finishes.
source
or .
take a file as parameter. Every line of code in that file is executed. So I don't think that
. ./
would work.
$ . ./
-bash: .: ./: is a directory
$ echo "echo Hello" > out
$ . out
Hello
$ source out
Hello
精彩评论