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.

share|improve this question
    
Can't search on Google because of the ;;, and haven't found a dupe here. – Έρικ Κωνσταντόπουλος yesterday
3  
Googled "sh double semicolon" ... stackoverflow.com/questions/16905183/… – muru yesterday
    
@muru Although not posted here yet I think. – Έρικ Κωνσταντόπουλος yesterday
up vote 36 down vote accepted

;; separates statements in a case...esac construct in Bourne-like 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).

share|improve this answer
    
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. – Έρικ Κωνσταντόπουλος 23 hours ago
    
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 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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