0

I have the following script:

$ cat test.sh
#! /usr/local/bin/bash
date

Run it,

$ test.sh
-bash: test.sh: command not found

It works

$ ./test.sh
Thu Oct 25 18:04:45 CST 2018

Nonetheless, I am aware that test.sh is identical to ./test.sh,

$ file test.sh
test.sh: Bourne-Again shell script text executable, ASCII text
$ file ./test.sh
./test.sh: Bourne-Again shell script text executable, ASCII text

What' the subtle difference between test.sh and ./test.sh?

Kusalananda
  • 333,661
Wizard
  • 2,503

1 Answers1

1

The two are not identical ways to run a command. With ./test.sh, you run the test.sh script in the current directory. With test.sh, you run the first found test.sh in your $PATH.

Had you called the script test, then running just test would have used the test utility that is likely built into your shell (which does not produce any output), whereas running ./test would have executed your script.

Related:

Kusalananda
  • 333,661