
正確なインデントと行を使用して、シェルスクリプトの変数に次の複数行の文字列値を割り当てたいと思います。
Usage: ServiceAccountName LogFile
Where:
ServiceAccountName - credentials being requested.
LogFile - Name of the log file
私は以下の提案に従い、これをやろうとしました。インデントを使用して複数行変数に文字列値を割り当てるには? しかし、結果はありません。提案してください。
REASON="$(cat <<-EOF
Usage: ServiceAccountName LogFile
Where:
ServiceAccountName - credentials being requested.
LogFile - Name of the log file
EOF
)"
echo "$REASON"
これは私のスクリプトです。
GetBatchCredentials.sh
if [ $# -ne 2 ]
then
# RETURN INVALID USAGE
GetBatchCredentials_Result="Error"
GetBatchCredentials_Reason="$(cat <<-EOF
Usage: ServiceAccountName LogFile
Where:
ServiceAccountName - credentials being requested.
LogFile - Name of the log file
EOF
)"
else
//coding...
fi
スクリプトは次のスクリプトから呼び出されます。
. /www/..../scripts/GetBatchCredentials.sh arg1 arg2
if [ "$GetBatchCredentials_Result" != "Success" ]
then
echo "Error obtaining FTP Credentials"
echo "$GetBatchCredentials_Reason"
ret=1
else
echo "Obtained Credentials"
fi
答え1
ここにドキュメントに役に立たない猫を追加する代わりに、
REASON="\
Usage: ServiceAccountName LogFile
Where:
ServiceAccountName - credentials being requested.
LogFile - Name of the log file"
または
REASON="$(printf '%s\n' \
"Usage: ServiceAccountName LogFile" \
"Where:" \
" ServiceAccountName - credentials being requested." \
" LogFile - Name of the log file")"
答え2
あなたのスクリプトは私にとって効果的です。私がしたことは、一番上に#!/ bin / shを追加しただけです。その後、実行可能にして実行します。 sh と元のスクリプトの名前も使用できます。
#!/bin/sh
REASON="$(cat <<-EOF
Usage: ServiceAccountName LogFile
Where:
ServiceAccountName - credentials being requested.
LogFile - Name of the log file
EOF
)"
echo "$REASON"