0

I would like to know what is the syntax error in this bash srcipt

#!/bin/bash
CURRENT=1594184400
while true do
  NEXT=$((CURRENT+300))
  CURRENT=$NEXT
done

That I get

syntax error near unexpected token `done'

error?

1
  • 1
    If you are new to shell scripting, I would recommend shellcheck, which is also available as standalone tool in many Linux distributions. Commented Jul 8, 2020 at 15:05

1 Answer 1

6

You either need a semicolon after true on the second line or to put do on the following line by itself.

Either this:

#!/bin/bash
CURRENT=1594184400
while true; do     
  NEXT=$((CURRENT+300))
  CURRENT=$NEXT
done

Or this:

#!/bin/bash
CURRENT=1594184400
while true 
do
  NEXT=$((CURRENT+300))
  CURRENT=$NEXT
done

You can check shell scripts for errors here:

https://www.shellcheck.net/

You can also run bash -n script on the terminal to check for errors.

1
  • Just to add why this is necessary, otherwise do is simply parsed as an argument to true, and the parser is still looking for the required keyword do in a command position when it encounters done. Commented Jul 8, 2020 at 18:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.