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

Re: sourcing a sh file in zsh




It turns out the error is indeed not in line #1, but a bit later:

  a_temp=`egrep "^[  ]*$a_host[    ]" "$a_root/somefile"`

If I change that line to

  a_temp=`egrep "^[  ]*${a_host}[    ]" "$a_root/somefile"`

the script passes fine, with exit code 0.

So perhaps sh/bash are more lenient towards the use of braces in
variables. At least a quick'n'dirty test script shows this.
I don't know; anyway can comment on that?

It's the opposite: zsh is more lenient about braces, turning $a_host[ ]
into an array expression with an incorrect subscript.  So your fix is
fine. Having "setopt ksharrays" would fix this, and this option is used
in compatibility modes, so indeed if you were in sh emulation as
explained by Bart this will work without modification. The emulation is
a much better general solution---there are other compatibility issues,
many of the most important of which are listed in the FAQ
(http://zsh.dotsrc.org/FAQ/zshfaq02.html#l10).

Brilliant!
Thanks all. I'm happy using zsh, but occasionally these things catch me out, and I find there are too many little things to learn about than I'm actually willing to, this being one example.
But the ksharrays option and sh emulation I'll try to keep in mind.

  Evert



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