What are the differences between commands "t.sh" ". t.sh" "/t.sh" "./t.sh"? [duplicate]

Solution 1:

  • for t.sh the shell will search the PATH in order for a file named t.sh and execute it if it finds it

  • for . t.sh the shell will search the PATH in order for a file named t.sh but source it if it finds it.

    In the case of the bash shell, the search behavior for sourced commands has additional considerations, as noted in 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.
  • for /t.sh the shell will look for file t.sh in the filesystem root directory / and attempt to execute it

  • for ./t.sh the shell will look for file t.sh in the shell's current working directory . and attempt to execute it

See also

  • What are the differences between executing shell scripts using “source file.sh”, “./file.sh”, “sh file.sh”, “. ./file.sh”?

  • What is the difference between sourcing ('.' or 'source') and executing a file in bash?