Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Purely POSIX test or [ cannot test this with exactly one invocation of the tool. The way you did it is how it should be done with POSIX [. Why do you think it's not good for you and you need "a single row"?
From the first { to the last ] your expression is syntactically valid, if only the variables expand to sane values. It tests something. If it doesn't behave as you expect then maybe you got the logic wrong; or the if statement; or where you define the variables. Please edit and post a complete example. What do you expect from it? How does it fail? What shell are you using to run this?
Hint: code that depends on the current time and date can be tested with faketime. Compare faketime '1999-01-02 12:34:56' date. Just use your script instead of date to see how the script behaves at the chosen moment in the past or in the future. See man 1 faketime.
test
or[
cannot test this with exactly one invocation of the tool. The way you did it is how it should be done with POSIX[
. Why do you think it's not good for you and you need "a single row"?{
to the last]
your expression is syntactically valid, if only the variables expand to sane values. It tests something. If it doesn't behave as you expect then maybe you got the logic wrong; or theif
statement; or where you define the variables. Please edit and post a complete example. What do you expect from it? How does it fail? What shell are you using to run this?faketime
. Comparefaketime '1999-01-02 12:34:56' date
. Just use your script instead ofdate
to see how the script behaves at the chosen moment in the past or in the future. Seeman 1 faketime
.test
: give the expression as arguments andecho $?
afterwards.