bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash -n doesn't seem to catch all syntax errors...


From: Bob Proulx
Subject: Re: bash -n doesn't seem to catch all syntax errors...
Date: Mon, 15 Oct 2007 16:37:10 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

Ken Failbus wrote:
> When I specify on command-line "bash -n <myscript name>". Bash doesn't
> check for valid syntax errors. E.g. if variable is missing a "$" infront
> of it while assigning a value. This is not catched by bash.

Unfortunately what you are describing is not a syntax error.  It is
perfectly valid syntax and in other contexts will be exactly what is
desired.

> Is there a more specific option that should be specified to bash to
> check for syntax errors.

Since that case is not an error it can't be caught in this way.  You
will simply need to test more thoroughly.

> ### example code
> p=hello
> e=world
> If [ p != $e ];then

You should quote the arguments to avoid the error that would be
produced from test if they were not set.

  if [ "$p" != "$e" ];then

>       echo "not equal"
> else
>       echo "equals"
> fi

Consider of this case:

  if [ "${a+set}" = set ]; then
    echo a is set
  else
    echo a is not set
  fi

There is no way for bash to differentiate "set" from "$set".  It will
do exactly what it is told to do and has no way to know what you
_want_ it to do.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]