This is my little demo
#!/bin/bash
read -p "Please input three numbers:" n1 n2 n3
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
then
echo "max_num is $n1"
elif [ $n3 -gt $n2 ] && [ $n1 -lt $n3 ]
then
echo "max_num is $n3"
else
echo "max_num is $n2"
fi
The error [: missing `]] is reported mainly for the following reasons:
Spaces shall be used between if and ‘[‘, ‘[‘ and condition, ‘]’ and condition, ‘-GT’ and the number to be compared before and after;
When using relational operators’ && ‘ or ‘ | ‘in the middle, be sure to enclose the conditions before and after with square brackets.
Similar Posts:
- Bash Shell: Check File Exists or Not [How to Do]
- Shell script execution error [: 0: unary operator expected
- Shell Syntax Error: operand expected (error token is “-”)
- Solutions to the problem of too many arguments in Linux Bash
- String null space error: binary operator expected
- [Solved] PythonTypeError: ‘<' not supported between instances of 'str' and 'int'
- The shell script reported an error: not sure operator expected
- [Solved] Shell Script [: -ge/-le/=/… : unary operator expected (standard_in) 1: syntax error
- How to Solve Git Error: “bash: $’\302\226git’: command not found”
- SQL Error: 1064, SQLState: 42000 [Three Methods to Solve]