命令“源”做什么?

时间:2019-05-16 05:18:10

标签: bash shell unix

我想知道命令 f = open("blah.txt", "a") subprocess.call(["python","loop.py"], stdout=f,stderr=f) 的作用。我尝试过:

  • 什么
source
  • man
$ whatis source
source: nothing appropriate.
  • 来源(-h,-help等)
$ man source
No manual entry for source

但是似乎没有关于它的文档。

我通常使用它来保存我的点文件中的所有更改,但是它究竟能做什么?为什么没有关于它的文档?

1 个答案:

答案 0 :(得分:1)

source是bash shell内置命令,用于执行作为参数传递的文件的内容, 在当前shell中 。它的缩写为.(句号)。

  

语法

. filename [arguments]

source filename [arguments]

摘自原始手册

source filename [arguments]
    Read and execute commands from filename in the current shell environment and
    return the exit status of the last command executed from filename. If 
    filename does not contain a slash, file names in PATH are used to find the
    directory containing filename. The file searched for in PATH need not be
    executable. When bash is not in posix mode, the current directory is
    searched if no file is found in PATH. If the sourcepath option to the short
    builtin command is turned off, the PATH is not searched. If any arguments
    are supplied, they become the positional parameters when filename is
    executed. Otherwise the positional parameters are unchanged. The return 
    status is the status of the last command exited within the script (0 if no
    commands are executed), and false if filename is not found or cannot be
    read. 

小心! ./source 不太相同

  • ./script将脚本作为可执行文件运行,启动新shell 来运行
  • source script当前shell 环境中从文件名读取并执行命令

注意:./script不是. script,而是. script == source script

Is there any difference between source in bash after all?