Answer the question
In order to leave comments, you need to log in
Bash - how to convert string to number?
Good afternoon! It is necessary to run different scripts with one command depending on the time of day.
To do this, I get hours using date hour = date +%H
And then I try to compare with a number
if [ hour < 20 ]; then echo 'true'; else echo 'false'; fi
Answer the question
In order to leave comments, you need to log in
Bash has no concept of strings/numbers. If there is a number inside, then it will parse this number.
Well, in the example from the solution, it is better to write ${todate}. And in general, it is always better to write variables in ${} - this is readable and saves you from a lot of errors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question