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

Re: My script almost works but spams the terminal its launched from if useing dash.



Hi,

Gene Heskett wrote:
> In normal everyday operation, the variable ${InMail} will not be empty.

Well, normally the 10 uF capacitors suffice for the projected
life time of the dishwasher. :))


The bashism "[[ ${InMail} = 'gene' ]]" hides the pitfall that whitespace
in a variable will normally yield more than word. (That's quite unexpected
from the general view of shell programming, but documented in man bash.)

With conservative shell gestures one should enclose variable evaluation
in " quotation marks in order to get the content as exactly one word:

  $ InMail="a b"
  $ if [[ ${InMail} = 'gene' ]] ; then echo yes ; else echo no ; fi
  no
  $ if test ${InMail} = 'gene'; then echo yes ; else echo no ; fi
  bash: test: too many arguments
  no
  $ if test "${InMail}" = 'gene'; then echo yes ; else echo no ; fi
  no

With empty text and no "-marks you get the contrary complaint about
0 words as evaluation result:

  $ InMail=""
  $ if test ${InMail} = 'gene'; then echo yes ; else echo no ; fi
  bash: test: =: unary operator expected
  no


Google "portable shell" tells me that the gesture

  test "x$variable" = xconstant

does not really target empty variable content but rather reserved
words as variable content.
The command test(1) (bash builtin or /usr/bin/test) seems to be quite
tolerant with syntax errors caused by reserved words where operants
are expected.
I fail to make it complain about content like
  $ InMail="("
  $ InMail="-f"
if i use proper "-marks.  


Have a nice day :)

Thomas


Reply to: