0

How to use test to test a expression like this:

if { [ $month -eq 03 ] || [ $month -eq 10 ]; } && [ $weekday = "So" ] && [ $day -gt 24 ]

I need to test the whole if statement in a single row.

Thanks in advance.

5
  • 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"? Commented Mar 30, 2021 at 14:17
  • No need a single row, but how to test the whole expression?
    – Omexlu
    Commented Mar 30, 2021 at 14:22
  • 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? Commented Mar 30, 2021 at 14:50
  • 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. Commented Mar 30, 2021 at 15:06
  • How to use test: give the expression as arguments and echo $? afterwards. Commented Mar 30, 2021 at 15:56

0

You must log in to answer this question.

Browse other questions tagged .