在bash脚本中,点后跟空格然后是路径是什么意思?
我尝试在openvz容器中安装usb设备时遇到了这个例子,我之前从未见过第二行中的构造。 你能解释一下它的含义吗?
#!/bin/bash . /etc/vz/vz.conf
它是内置source
的同义词。 它将从当前shell中的文件执行命令 ,从help source
或help .
读取help .
。
在您的情况下,将执行文件/etc/vz/vz.conf
(很可能,它只包含稍后将在脚本中使用的变量赋值)。 它不同于仅使用/etc/vz/vz.conf
以多种方式执行文件:最明显的是文件不需要是可执行的; 然后你会想到用bash /etc/vz/vz.conf
来运行它,但是这只会在子进程中执行它,并且父脚本不会看到子进程的任何修改(例如变量)。
例:
$ # 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" hello $
希望这可以帮助。
当使用`source’运行脚本时,它在现有shell中运行,脚本完成后,脚本创建或修改的任何变量都将保持可用。
句法 。 文件名[参数]
source filename [arguments]