LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash scripting options double semicolon (https://www.linuxquestions.org/questions/linux-newbie-8/bash-scripting-options-double-semicolon-4175600617/)

secomax 02-26-2017 07:12 AM

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.

hydrurga 02-26-2017 07:33 AM

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.

secomax 02-26-2017 08:37 AM

thanks for the reply.

hydrurga 02-26-2017 08:48 AM

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.


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