Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .