命令“t.sh”“.t.sh”“/t.sh”“./t.sh”有什么区别?

Mel*_*ron 8 command-line scripts

我是贝壳新手,所以我一直在问这种问题。区分这些命令的最简单方法是什么?

ste*_*ver 12

  • 因为t.shshell 将按PATH顺序搜索命名的文件t.sh,如果找到就执行它

  • 因为. t.shshell 将按PATH顺序搜索命名的文件,t.sh但如果找到它,则将其作为文件。

    在 bash shell 的情况下,源命令的搜索行为有额外的考虑,如man bash

  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  shopt  builtin  command  is turned off, the PATH is not
  searched.
Run Code Online (Sandbox Code Playgroud)
  • 因为/t.shshell 将t.sh在文件系统根目录中查找文件/并尝试执行它

  • 因为./t.shshell 将t.sh在 shell 的当前工作目录中查找文件.并尝试执行它

也可以看看