1

I have a function printing a number

myFunc() {
    echo 11
}

Now I want to use the number in expression in c style for-loop:

for (( i=1; i<=$(myFunc); i++ )); do
    echo "$i"
done

Zsh gave me

test.sh:5: parse error near `i++ '
test.sh:6: parse error near `i<=$(myFunc); i++ ))...'

while Bash prints 1 through 11 as expected. What happened to Zsh? I expect it to be compatible with Bash on this feature.

In case it matters, my environment:

  • OS X 10.11.5
  • zsh 5.0.8 (x86_64-apple-darwin15.0)
  • GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)

update

This may be a bug, and may have been fixed in latest version. I will delete this question as soon as I verify this.

9
  • 1
    A general pondering: Why would you write code for one language and expect it to be understood by the interpreter of another? Just make the script run in bash.
    – Kusalananda
    Jul 1, 2016 at 8:38
  • @Kusalananda How about completion? I run those script with source filename. It would take a lot of time to translate it to Zsh. Jul 1, 2016 at 8:56
  • @jimmij So it seems that I need to update my Zsh? I will try the latest version. Jul 1, 2016 at 8:56
  • 2
    @Kusalananda I am already using Oh-My-Zsh, but I forgot that it involves completion. I found the plugin I need. Thank you very much! I will delete this question as soon as I verify that it is a bug already fixed in latest version. Jul 1, 2016 at 9:17
  • 1
    Don't delete it! That would prevent others to find the issue. Instead, answer it yourself and in two days time (required waiting period), accept your own answer.
    – Kusalananda
    Jul 1, 2016 at 9:19

1 Answer 1

0

It works in my zsh:

$ zsh --version
zsh 5.7.1 (x86_64-pc-linux-gnu)
$ myFunc() {
    echo 11
}
$ for (( i=1; i<=$(myFunc); i++ )); do
    echo "$i"
done
1
2
3
4
5
6
7
8
9
10
11
$ 

It might just have been a bug.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .