HOSTNAMEこの式は、が設定されていないかどうかをチェックします。
[ "x" = "x$HOSTNAME" ]
が設定されていない場合HOSTNAME、これは次のようになります。
[ "x" = "x" ]
もちろん、これは に評価されtrueます。表現:
[ "x" = "x$HOSTNAME" ] && HOSTNAME=`env hostname`
前の式が の場合のHOSTNAME出力に設定されます。呼び出しは、単にローカル ホストの名前を出力するだけの呼び出しとまったく同じです。env hostname&&trueenv hostnamehostname
2 番目の式:
NODENAME=rabbit@${HOSTNAME%%.*}
変数展開を使用しbashて、ホスト名の最初のコンポーネント以外をすべて削除しています。を指定するとHOSTNAME="host.example.com"、${HOSTNAME%%.*}が返されますhost。詳細については、bashman ページを参照してください。
${parameter%%word}
Remove matching suffix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then
the result of the expansion is the expanded value of parameter
with the shortest matching pattern (the ``%'' case) or the longest
matching pattern (the ``%%'' case) deleted.
したがって、ローカル ホスト名が であると仮定すると、これは に設定NODENAMEされます。rabbit@hosthost.example.com