これは私のコマンドです:
mail_recipient_location="$PWD/mail_config/myFile.txt"
textVariable= [ -f "$mail_recipient_location" ] && `cat "$mail_recipient_location"`
私の端末にcat
返品が表示されます。
{the mail's adress's value in myFile.text}: command not found
cat
ファイルテキスト値をtextVariableに挿入するにはどうすればよいですか?
ベストアンサー1
set -x
スクリプトを使用またはデバッグすると、次のようにbash -x
印刷されます。
+ mail_recipient_location=/somepath/mail_config/myFile.txt
+ textVariable=
+ '[' -f /somepath/mail_config/myFile.txt ']'
++ cat /somepath/mail_config/myFile.txt
+ the mail's adress's value
評価後
[ -f "$mail_recipient_location" ]
Quasimodoがすでに述べたように、これはあなたを拡張してcat "$mail_recipient_location"
無視します。したがって、実行したいコマンドではないようですtextVariable=
。the mail's adress's value
必要なものを達成するには、次のものを使用できます。 (また、以下を避けるべきです。ウルムチ大学):
# oneliner
[ -f "$mail_recipient_location" ] && textVar=$(<"$mail_recipient_location")
# or
if [ -f "$mail_recipient_location" ]; then
textVar=$(<"$mail_recipient_location")
else
: # do something
fi
非POSIX、次に適用bash
可能zsh