In the shell script, when comparing with parameters, such as "[$temp-eq" IPhone "]", there may be an "integer expression expected" error. This is because these parameters:-GT,-lt,-eq comparisons are both numbers and variables, so the variable temp if it is a string, this error occurs. Change the original sentence to "[$temp-eq IPhone]" and the result is the same.
To solve this problem, we can take a more circuitous approach, that is, use the awk tool to compare the variables, return the results of comparisons, and compare the results with the corresponding numbers. The above examples can be handled in this way:
[' Echo ${temp} | awk-v tem= ' iPhone ' {print ($1>tem)? "1": "0"} '-eq "0"]
Full version:
If [' Echo ${var} | awk-v tem= ' iphone9,2 ' {print ($1>tem)? "1": "0"} '-eq "0"]
then
echo iPhone 7 Plus
else echo unrecognized
device
fi