If I try to run a;;b in sh, I get this error:

sh: <number>: Syntax error: ";;" unexpected

If I try a;;;b I get the same error, not ;;; instead of ;;, so I think that ;; means something, although I don't know what does it mean.

Here is an example:

$ echo A;;echo B
sh: 1: Syntax error: ";;" unexpected
$ echo A;;;echo B
sh: 1: Syntax error: ";;" unexpected
$ echo A; ;echo B
sh: 1: Syntax error: ";" unexpected

Here you can see that when I use ; ; instead of ;; the error is different, pertaining to the fact that I used ; without a command before. ;; seems to be a different operator, although I don't know what it applies to.

  • 1
    Can't search on Google because of the ;;, and haven't found a dupe here.
    – EKons
    Apr 18, 2017 at 10:48
  • 3
    Googled "sh double semicolon" ... stackoverflow.com/questions/16905183/…
    – muru
    Apr 18, 2017 at 10:51
  • @muru Although not posted here yet I think.
    – EKons
    Apr 18, 2017 at 10:52
  • @ΈρικΚωνσταντόπουλος That's what SymbolHound is for symbolhound.com
    – Joe
    Apr 22, 2017 at 5:00

1 Answer 1


;; separates statements in a case...esac construct in POSIX shells:

case foo in (a) cmd1; cmd2 ;; (b) cmd3; cmd4; esac

To find out about a command, you can run man that-command. If your pager is less, you can search within the man page by pressing /.

Here, you'd run man sh and search for ;;. Some shells support other operators to separate case statements (like ;& in ksh93/zsh/bash/mksh, &| in zsh/mksh, ;;& in bash).

  • 1
    I just posted here because I think there should be such a question here anyways, since here it could be explained in a clearer way if someone is confused.
    – EKons
    Apr 18, 2017 at 10:59
  • 2
    If there are lots of hits, or you can't remember the escaping rules for searching with less, it's sometimes handy to $ man bash|grep -C1 ';;'
    – unhammer
    Apr 19, 2017 at 9:20
  • You shouldn't have ( before a) and b), and you need ;; after cmd4
    – Barmar
    Apr 19, 2017 at 18:56
  • @Barmar, that syntax is POSIX. In the Bourne shell, you had to omit the ( indeed, but you still didn't need the ;; before esac (though it didn't harm). Apr 19, 2017 at 19:29
  • Thanks. I didn't know about that change in POSIX shell, or that the last ;; was optional.
    – Barmar
    Apr 19, 2017 at 19:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.