Re: Suspend-sedation Problem
Quoting Eirik Schwenke (eirik@schwenke.info):
> Then there was a different change, to do numerical comparison against date +%%s. I think the new code contains two errors: a) it should be:
>
> NOW="$(date +%s)";
>
> At least my date complains that % isn't a valid number if "+%%s" is used. Probably a simple typo.
>
> In the case that no wake-alarm is set; WAKEALARM will be the empty string and dash (and bash) will complain that an integer expression is expected. As far as I can tell adding a test for the empty string (-z) and chaining with logical-or (-o) will *not* work:
>
> a=""
> if [ -z "${a}" -o 10 -ge "${a}" ]
bash and dash both support default values for unset/null parameters,
so you can write ${a:-0} or whatever.
${parameter:-word} Use Default Values. If parameter is unset or null,
the expansion of word is substituted. Otherwise, the value of
parameter is substituted.
You can only dodge a syntax error by a short-circuiting OR; leaving it
until you evaluate the test is too late. Thus
if [ ... ] || [ ... bad syntax here ... ]
then
would work but I wouldn't use that construction here. It's really
designed for cases where evaluating the second test would cause an
undesired side-effect.
Cheers,
David.
Reply to: