Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell编程基础知识总结关系运算符部分示例代码勘误 #2653

Open
silverstarshining opened this issue Mar 29, 2025 · 0 comments

Comments

@silverstarshining
Copy link

示例代码无法正常运行,会报错[: 90: unary operator expected,但是底部的截图是正确的,可能是少打了?
原因是变量可能为空,于是产生中括号与另一个变量相比从而缺少中括号的情况,应改为[[ ]]
示例代码如下
`#!/bin/bash

score=90
maxsscore=100
if [[ $score -eq $maxscore ]]
then
echo "A"
else
echo "B"
fi`
运行结果

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant