nvmを介してノードをインストールするとき、.profileファイルで次のコマンドが見つかりました。
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[]
次のコマンドで中和の目的が何であるかを知りたいです。&&
以前このコマンド構文に触れたことはありません。次のコマンドの機能とこの構文の名前を知りたいです。私の考えでは、ソフトリンクを生成するようです。そうですか?
編集する:nvm.sh は実行ファイルではありません。
ベストアンサー1
[
テスト構造は次のとおりです。
$ help [
[: [ arg... ]
Evaluate conditional expression.
This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
これは-s
利用可能なテストの1つで、ファイルが存在し、空でない場合はtrueを返します。
$ help test | grep -- -s
-s FILE True if file exists and is not empty.
&&
ANDですオペレーター。右側のコマンドは、左側のコマンドが成功した場合にのみ実行されます。
最後に、この.
コマンドは、source
同じシェルセッション内のソースファイル内のすべてのコードを評価するようにシェルに指示します。
$ help .
.: . filename [arguments]
Execute commands from a file in the current shell.
Read and execute commands from FILENAME in the current shell. The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.
したがって、実行したコマンドは次のようになります。
## If the file exists and is not empty
if [ -s "$NVM_DIR/nvm.sh" ]; then
## Source it
. "$NVM_DIR/nvm.sh"
fi