Bashスクリプトの「予期しないファイルの終わり」

Bashスクリプトの「予期しないファイルの終わり」

Bashスクリプトに以下がある場合:

if [ $ACTION = deploy ]; then
    ${JAVA_HOME}/bin/java ${JVM_ARGS} weblogic.WLST << EOJ
    connect('XXX','XXX','t3://XXX:8001')
    jndi();
    ls();
    disconnect();
    exit ();
    EOJ
else
    echo "XXX"
fi

EOJにエラーがあるようです。

ベストアンサー1

EOJ完全に左揃えする必要があります。先行スペースと末尾スペースはありません。または(必要に応じて)最初の項目を.として書くこともできます<<'EOJ'。引用符は、いくつかの可能なシェル拡張を無効にします。

~からinfo bash

Here Documentsこのタイプのリダイレクトは、区切り文字のみを含む行(末尾の空白なし)が表示されるまで、現在のソースから入力を読み取るようにシェルに指示します。この時点までに読み込まれたすべての行は、コマンドの標準入力として使用されます。

   The format of here-documents is:

          <<[-]word
                  here-document
          delimiter

   No  parameter expansion, command substitution, arithmetic expansion, or
   pathname expansion is performed on word.  If any characters in word are
   quoted,  the  delimiter is the result of quote removal on word, and the
   lines in the here-document are not expanded.  If word is unquoted,  all
   lines  of  the here-document are subjected to parameter expansion, com‐
   mand substitution, and arithmetic expansion.  In the latter  case,  the
   character  sequence  \<newline> is ignored, and \ must be used to quote
   the characters \, $, and `.

   If the redirection operator is <<-, then all leading tab characters are
   stripped  from  input  lines  and  the line containing delimiter.  This
   allows here-documents within shell scripts to be indented in a  natural
   fashion.

おすすめ記事