0
cd  /tmp
vim  test.sh
#!/bin/bash
echo "test me"

I have edited a file named test.sh.

./test.sh
test me

The . means current directory which is /tmp here, ./test.sh can execute it.
Why . test.sh can execute it too,there are several blank whitespace between . and test.sh?

.   test.sh
test me
  • `.` is the command [called `dot` in the POSIX spec](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#dot). Bash also has it available under the name `source`. It's not referring to the local directory, in your usage -- it's referring to the shell builtin. – Charles Duffy Jun 12 '18 at 01:47
  • 1
    ...contrary to the test described in the question, it's not actually the same as `./test.sh`; try something like `cd /` in the script -- when you dot it, you'll see that it changes your parent interpreter's directory (because the commands in the script were run *inside that preexisting interpreter*, not in a shell started as a child process). – Charles Duffy Jun 12 '18 at 01:50

0 Answers0