答案 0 :(得分:1)
您应该在shebang(zsh
)行中指定#!
- 并且您可以使用/usr/bin/env
来确定可移植的位置(ish)。并且比较数值的运算符是-lt
,-gt
和-eq
小于,大于等于。我还希望printf
超过echo
。总而言之,我想你想要
#!/usr/bin/env zsh
printf "Please enter an integer ->"
read A
B=99
printf "B=%d\n" $B
if [[ "$A" =~ ^-?[0-9]+$ ]]; then
if [[ "$A" -gt "$B" ]]; then
printf "A>B (%d>%d)\n" "$A" "$B"
elif [[ "$A" -lt "$B" ]]; then
printf "A<B (%d<%d)\n" "$A" "$B"
else
printf "A=B (%d=%d)\n" "$A" "$B"
fi
else
printf "A (%s) is not an integer\n", "$A"
fi