LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-26-2017, 08:12 AM   #1
secomax
LQ Newbie
 
Registered: Feb 2017
Posts: 15

Rep: Reputation: 0
bash scripting options double semicolon


Hi
I have a small question about bash scripting
this is the snippet I'm asking about
Code:
#!/bin/bash
echo
while [ -n "$1" ]
do
case "$1" in
-a) echo "Found the -a option" ;;
-b) echo "Found the -b option" ;;
-c) echo "Found the -c option" ;;
*) echo "$1 is not an option" ;;
esac
shift
done
I got this from a tutorial https://likegeeks.com/linux-bash-scr...e-guide-part3/

Why do we need double semicolon after each option
I tried to remove the semicolon it gives me this error
Code:
syntax error near unexpected token `)'
thanks in advance.
 
Old 02-26-2017, 08:33 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19 MATE
Posts: 6,243
Blog Entries: 2

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
You need the double semicolon at the end of each case clause because that is what bash syntax requires in order to parse the command correctly.

http://tldp.org/LDP/Bash-Beginners-G...ect_07_03.html

Remember that each case clause may have multiple statements within that clause, each terminated with an optional semicolon. Bash needs to know when the clause itself is finished, hence the double semicolon.
 
2 members found this post helpful.
Old 02-26-2017, 09:37 AM   #3
secomax
LQ Newbie
 
Registered: Feb 2017
Posts: 15

Original Poster
Rep: Reputation: 0
thanks for the reply.
 
Old 02-26-2017, 09:48 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19 MATE
Posts: 6,243
Blog Entries: 2

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
Glad to help, secomax.

If you consider your question solved then you can mark the thread accordingly using "Thread Tools" at the top of the thread.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 09:03 AM
what are the options with double hyphen xombboxer Linux - Newbie 4 03-14-2012 01:36 AM
bash: execute a semicolon separated list of commands within string Meson Linux - General 3 10-02-2008 12:25 AM
semicolon bash kalleanka Programming 3 11-02-2006 10:09 AM
What are those double-dash (--) options in man? Utah Linux - Newbie 4 06-04-2004 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration