シェルスクリプトでコマンドが見つかりません

シェルスクリプトでコマンドが見つかりません

変数値を出力できない理由を教えてください。

# chmod 777 chkscript.sh
# ./chkscript.sh

chkscript.sh文書内容

variable = "This is variable"

echo "$variable"

echo "Hello World "

出力:

# ./chkscript.sh
./chkscript.sh: line 5: variable: command not found

Hello World
#

添付: 時々

 variable1 = "/home/files" --- which is location if I try to print nothing gets printed.
 echo "$variable"

ベストアンサー1

=シェルでは、変数の割り当ての両側にスペースは使用できません。

この試み:

variable="This is a variable"

前にスペースを残すと、=シェルは以前のトークンをコマンドまたは関数名として解釈するため、「コマンドが見つかりません」というメッセージが表示されます。

おすすめ記事