-3

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?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Anmol
  • 123
  • 4
  • 1
    This might help: `help .` – Cyrus Dec 18 '16 at 18:18
  • It is possible to use `.` (`source`) builtin bash command without full or relative path to file: `. vars` but in such case `.` command does searching of its argument in directories listed in `$PATH` variable. When your file has name which can be used in some system bin directory, wrong file can be selected: `. echo` or `. ./echo`. – osgx Dec 18 '16 at 18:39
  • I think that disregarded lines look like `dir="/home/someone"`. These lines are not disregarded (lines starting with a `#` are skipped, they are comments), but executed: It will give the `var` with the name `dir` the value on the right side of `=` (no spaces around `=`). You can try `echo "me=${me}"; me=Anmol; echo "me=${me}"`. – Walter A Dec 18 '16 at 21:34
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306) – jww Dec 19 '16 at 03:44

3 Answers3

1

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

shadowtalker
  • 12,529
  • 3
  • 53
  • 96
  • 3
    It would be more accurate to say that `source` is an (optional) synonym for `.`, since `.` is the canonical name for the command. (See [posix](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#dot).) – rici Dec 18 '16 at 18:09
0

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

Community
  • 1
  • 1
Max
  • 1,325
  • 9
  • 20
0

. 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

0.sh
  • 2,659
  • 16
  • 37