how does " . ./filename " command work

77 Views Asked by At

I was following a tutorial on openvpn and it needed to execute a command . ./vars. It displays a message. On reading the file I found that it executes a echo command in file and disregards everything else in file. On adding other echo statement, it also gets executed. So i would like some basic explanation on this. Is this something related to bash only?

3

There are 3 best solutions below

0
On

. sources or imports a bash script to the current script you are working on ( if you are creating a script ) or to the current tty ( terminal or command line ) if you are working with the commandline interface. The script it is sourcing must be an executable ( it should have the -x flag set )

./filename means find filename in the present directory am in. if you execute only ./filename in tty ( terminal or command line ) or inside a script, it finds filename and check if filename is executable, then it runs filename . You should take not that ./ means the present working directory. Using two dots ( ../filename ) instead of one with filename tells the bash parser go to the previous directory before the present one am in

using . ./filename you are telling the bash parser to import or source (.) filename (./filename ) in the directory you are currently on

1
On

. and source are synonymous: it just runs the file line-by-line in the current shell. ./vars is just a path to some file named vars in the current directory. So all that command does is run the file vars line-by-line.

As for the rest of your question, I don't really understand what you're asking. Can you clarify?

0
On

The . at the start has an explanation here, and the ./filename is a relative reference to the file.