1

If I execute this bash script:

#!/bin/bash
j=0
for(( i=1;i<(j);i++ ))
do
  echo j
done

I get:

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

I know that the problem are the extra parenthesis at (j), but I would like to understand why it detects the error at line 6, not 3. What is the logic here?

  • 4
    It seems that the <( is the issue. Adding a space in between will remove the error. I wonder if the parser gets confused about a process substitution inside an arithmetic expression? – glenn jackman Jun 18 '18 at 18:40
  • FWIW your code appears to execute without error in bash 4.4.12 but not in bash 4.3.48 – steeldriver Jun 18 '18 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.