[kwlug-disc] Outsmarted by bash && if

Robert P. J. Day rpjday at crashcourse.ca
Wed Apr 7 21:23:19 EDT 2010

On Wed, 7 Apr 2010, Lori Paniak wrote:

> Dear very clever list,
> I am trying to write a simple bash script to (re)start a process given
> the logical "and" of two conditions.  I think it should look like this:
> if [ -n "$STICK" ] && [ -n "$STATUS" ]; then
> 	      /sbin/ifup ppp0
> fi
> When STICK and STATUS are non-empty strings I would like ifup to run.
> This works if I just use one condition, but I cannot figure out the
> correct syntax for the AND-ed case.  I've tried (seemingly) all
> combinations and locations of brackets without success.
> Anyone out there care to point out my trivial error(s)?

  i'm not sure why it *doesn't* work.  if i use hardcoded strings:

$ if [ -n "fred" ] && [ -n "barney" ] ; then
> echo yup
> fi

so i'm not sure what the deal is.


Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday

More information about the kwlug-disc mailing list