LinuxQuestions.org
Review your favorite Linux distribution.
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, 07: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, 07:33 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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.
 
3 members found this post helpful.
Old 02-26-2017, 08:37 AM   #3
secomax
LQ Newbie
 
Registered: Feb 2017
Posts: 15

Original Poster
Rep: Reputation: 0
thanks for the reply.
 
Old 02-26-2017, 08:48 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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 08:03 AM
what are the options with double hyphen xombboxer Linux - Newbie 4 03-14-2012 12:36 AM
bash: execute a semicolon separated list of commands within string Meson Linux - General 3 10-01-2008 11:25 PM
semicolon bash kalleanka Programming 3 11-02-2006 09:09 AM
What are those double-dash (--) options in man? Utah Linux - Newbie 4 06-04-2004 10:53 PM

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

All times are GMT -5. The time now is 02:30 PM.

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
Open Source Consulting | Domain Registration