
변수값을 출력할 수 없는 이유를 알려주세요.
# 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"
앞에 공백을 남겨두면 =
쉘은 이전 토큰을 명령 또는 함수 이름으로 해석하므로 "명령을 찾을 수 없음" 메시지가 표시됩니다.
답변2
비슷한 문제가 있어서 이렇게 했습니다.
#!/bin/sh
my_chars='This is test' ;
echo $my_chars
~
지금
$ ./test_chars.sh
This is test