Johnny
Johnny

Reputation: 11

Whats does this command mean in Unix?

What does it mean in Unix when you use . ./<filename>?

Thanks for the help

Upvotes: 1

Views: 3101

Answers (4)

sepp2k
sepp2k

Reputation: 370102

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.

Upvotes: 1

Jeremiah Willcock
Jeremiah Willcock

Reputation: 30969

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.

Upvotes: 1

monojohnny
monojohnny

Reputation: 6171

". ./?" 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.

Upvotes: 3

Donovan
Donovan

Reputation: 6122

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

Upvotes: 0

Related Questions