Skip to content
Advertisement

Bash for loop with Parenthesis working in linux and not in Git Bash

i have simple bash loop which is working fine in linux and not in local Git Bash which based on cygwin in windows
i have this for loop :

  #!/bin/bash

    for (i=2; i<4; ++i); do
        echo "dddd"
    done

in Git Bash it gives me this error :

./test.sh: line 5: syntax error near unexpected token `newline'
./test.sh: line 5: ` done

linux version of bash

Amazon Linux version 20xx.0x is available. [user1 ~]$ bash –version GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later

Git bash version

GNU bash, version 4.3.46(2)-release (i686-pc-msys) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Advertisement

Answer

Need TWO parentheses:

#!/bin/bash

for ((i=2; i<4; ++i)); do
    echo "dddd"
done
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement