Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run foo if and only if the current day of the month is less than the 7th.

So something like:

[ (/bin/date +'%-d') -le 7 ] && foo

Except that gives me a syntax error. The date part is coming out right, so I'm asking for the right syntax for the conditional test.

share|improve this question
up vote 3 down vote accepted
[ $(/bin/date +'%-d') -le 7 ] && foo

The $() syntax will execute the statement within the parenthesis and return the result, which is what you want.

share|improve this answer
Thanks a lot! I missed the $. – Sean Mar 26 '12 at 15:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.