I got this return -
bash: syntax error near unexpected token `;'
how do I fix this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The semicolon terminates a command. Usually you don't need it, since a newline will do. But you can use to put multiple commands on one line, e.g.
$ echo -n "hi "; echo there hi there
or maybe more usefully:
if [ whatever ]; then
Putting a semicolon at the start of a line leaves an "empty" command before it, and apparently the shell syntax forbids it. Yash gives a useful error message:
$ yash -c '; echo hi' yash -c:1: syntax error: a command is missing before ‘;’
And Ksh and Zsh seem to just ignore the issue:
$ zsh -c '; echo hi' hi
(But you can't use
echo foo;; in those either, since
;; is different from
> is different from
;; is used in
The empty command doesn't do anything anyway, so you can just leave the leading semicolon out. Or switch to Zsh, I guess.
It is the same syntax error as:
$ ; bash: syntax error near unexpected token `;'
Which simply means that there should be a
cmd before the terminating
$ ls ;
In such cases the
; is a metacharacter that is defined as:
A character that, when unquoted, separates words.
Not equivalent to the
; in the compound command:
if list; then list; else list; fi
As, in this case, it is part of the syntax of the command.