Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zsh syntax check fails on correct if [[ usage (rhbz 966911)



Hello zsh team,

I'd like to report a bug originally filed in https://bugzilla.redhat.com/show_bug.cgi?id=966911:

Description of problem:

zsh syntax check fails on simple script, which is syntactically OK, but zsh -n returns 1

Version-Release number of selected component (if applicable):

zsh-4.3.10-5.el6.x86_64

How reproducible:

always

Steps to Reproduce:
1. create a script

$ cat /tmp/test.zsh
#!/bin/zsh

if [[ $# -eq 1 ]]
then
  THE_USER=$1
else
  THE_USER=$(whoami)
fi

2. execute test
$ zsh -n /tmp/test.zsh

3. observe exit value
$ echo $?
1

Actual results:

1

Expected results:

0

Additional info:

Upstream zsh-5.0.0, zsh-5.0.2 behaves the same way.

The exitvalue is 0 if we provide exactly one argument:

$ zsh -n /tmp/test.zsh
$ echo $?
1
$ zsh -n /tmp/test.zsh aaa
$ echo $?
0
$ zsh -n /tmp/test.zsh aaa ddd
$ echo $?
1

The exitvalue is 0 if we add one line e.g.:

$ cat /tmp/test.zsh
#!/bin/zsh

if [[ $# -eq 1 ]]
then
  :
  THE_USER=$1
else
  THE_USER=$(whoami)
fi

or if we don't use $(command) construct in `else` branch.


If '[' test instead of '[[' is used, the syntax check returns OK, however '[[' syntax is recommended by manual, so the check should work as expected for '[[' as well.

Thanks and Regards

Filip

--
Filip Krška

GSS-SEG EMEA engineer, #sbr-shells (pri), #sbr-anaconda (sec)
Red Hat Czech s.r.o.
Purkyňova 99/71
612 45, Brno, Czech Republic
email:fkrska@xxxxxxxxxx
office phone:+420 5322 94499

♡ All Wrongs Reversed
http://copyheart.org



Messages sorted by: Reverse Date, Date, Thread, Author