왜 "정수 표현식이 필요합니다"라고 말하는지 이해가 안 됩니다.

왜 "정수 표현식이 필요합니다"라고 말하는지 이해가 안 됩니다.

그럼 이게 내 코드야

#!bin/bash

PS3='Pick the one you like and we will continue: '

select color in "Blue" "Black" "Orange" "Yellow"
do
echo "You selected $color"
break
done

echo

var=":"

echo "Alrighty, please type in the password as you have specified the    color $color"

read var

until  [ "$var" -ne password ] 
do
echo "You have specified a wrong password, and a wrong color please leave the script the script"
break
done

터미널은 다음과 같이 응답합니다.

1) Blue
2) Black
3) Orange
4) Yellow
Pick the one you like and we will continue: 1
You selected Blue

Alrighty, please type in the password as you have specified the color Blue
23
/root/Desktop/Bash/Test_1.sh: line 16: [: password: integer expression  expected
You have specified a wrong password, and a wrong color please leave the script

답변1

당신은 일을:

[ "$var" -ne password ]

-ne[(같지 않음)은 즉 양쪽이 정수일 것으로 예상하는 정수 연산자입니다 .

그러나 var=":"처음에는 read사용자 입력을 -ing하고 에 넣는 경우에도 var입력이 정수가 아니므로 오류 메시지가 발생할 수 있습니다.

어쨌든 정수라면 그 password자체가 문자열이기 때문에 검사가 실패합니다.

문자열이 같은지 비교하려는 경우 연산자는 다음과 같습니다 =.

[ "$var" = password ]

불평등:

[ "$var" != password ]

관련 정보