シェルでは、違いは何ですか?
. executable
と
./executable
最初のものでは、ドットはショートカットsourceですよね? と の間に違いは./executableありsource executableますか?
シェルでは、違いは何ですか?
. executable
と
./executable
最初のものでは、ドットはショートカットsourceですよね? と の間に違いは./executableありsource executableますか?
./executableとソース実行可能ファイルに違いはありますか?
基本的な違いは、
./foo.sh - foo.sh will be executed in a sub-shell
source foo.sh - foo.sh will be executed in current shell
いくつかの例は、違いを説明するのに役立つ可能性があります。
私たちが持っているとしましょうfoo.sh:
#!/bin/bash
VAR=100
ソース:
$ source foo.sh
$ echo $VAR
100
もし、あんたが :
./foo.sh
$ echo $VAR
[empty]
もう一つの例、bar.sh
#!/bin/bash
echo "hello!"
exit 0
次のように実行した場合:
$ ./bar.sh
hello
$
しかし、あなたがそれを調達する場合:
$ source bar.sh
<your terminal exits, because it was executed with current shell>
2番目にパスを指定します。./現在の作業ディレクトリであるPATHため、実行可能ファイルではなく現在のディレクトリを検索します。
source実行可能ファイルをパラメーターとして受け取り、現在のプロセスで実行します。