`test.sh`と`./test.sh`の微妙な違いは何ですか?

`test.sh`と`./test.sh`の微妙な違いは何ですか?

次のスクリプトがあります。

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

走る、

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

効果がある

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

それでも私はそれがtest.sh同じであることを知っています./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

test.shとの微妙な違いは何ですか./test.sh

ベストアンサー1

コマンドを実行するこの2つの方法は同じではありません。を使用すると、現在のディレクトリからスクリプトを実行./test.shできます。test.shtest.sh実行できます。test.sh$PATH

scriptを呼び出すと、testrunはシェルに組み込まれているユーティリティをtest使用し(出力なし)、runはスクリプトを実行します。test./test

関連:

おすすめ記事