Ubuntu – In a bash script what does a dot followed by a space and then a path mean

bashcommand lineopenvz

I came across this example when trying to mount a usb device inside a openvz container and I have never seen the construct in the second line before. Can you explain what it signifies?

. /etc/vz/vz.conf

Best Answer

It's a synonym of the builtin source. It will execute commands from a file in the current shell, as read from help source or help ..

In your case, the file /etc/vz/vz.conf will be executed (very likely, it only contains variable assignments that will be used later in the script). It differs from just executing the file with, e.g., /etc/vz/vz.conf in many ways: the most obvious is that the file doesn't need to be executable; then you will think of running it with bash /etc/vz/vz.conf but this will only execute it in a child process, and the parent script will not see any modifications (e.g., of variables) the child makes.


$ # Create a file testfile that contains a variable assignment:
$ echo "a=hello" > testfile
$ # Check that the variable expands to nothing:
$ echo "$a"

$ # Good. Now execute the file testfile with bash
$ bash testfile
$ # Check that the variable a still expands to nothing:
$ echo "$a"

$ # Now _source_ the file testfile:
$ . testfile
$ # Now check the value of the variable a:
$ echo "$a"

Hope this helps.