I have an if statement I need to run, as long as the value I have stored in my $counter
variable is greater than 5
.
Here is the respective section of my current (non-functioning) script:
if $counter > 5 then echo "something" fi
The mistake I'm making is probably very obvious, but for some reason I couldn't find the solution online.. Thanks!
You can take the same or different values as per your choice. Then we have initialized the “if” statement to contrast the two variables by an operator “-eq”. This will check whether the two variables are equal or not. If the two variables are equal, it will show the message displayed within the first echo phrase.
When comparing strings in Bash you can use the following operators: string1 = string2 and string1 == string2 - The equality operator returns true if the operands are equal. Use the = operator with the test [ command. Use the == operator with the [[ command for pattern matching.
Well that is quite simple:
if [ "$counter" -gt 5 ] then echo "something" fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With