Sunday, 25 October 2020

Bash Scripting with Switch Case Statement

Bash Scripting

In Linux, all tasks from execution of services to loading and unloading of modules are carried out by programs and all programs need to be executed. You use the commands to access all the basic features of kernel. Shell scripting is a way to automate such tasks, and bash is one of the language, that has capabilities enough to be called as scripting as well as a language that can be used for programming on the POSIX platform, for small tasks.  Bash Scripting else if statement


Using Case Statement

Case statement is used as the alternative of if-elseif-else statement. The starting and ending block of this statement is defined by ‘case’ and ‘esac’. Create a new file named, ‘case_example.sh’ and add the following script. The output of the following script will be same to the previous else if example.

echo "Enter your lucky number"
read n
case $n in
echo echo "You got 1st prize" ;;
echo "You got 2nd prize" ;;
echo "You got 3rd prize" ;;
echo "Sorry, try for the next time" ;;

Run the file with bash command.



echo "Enter a days name"
read m

case $m in monday)
echo "it's a monday time" ;;
echo "it's a tuesday time" ;;
echo "it's a wednesday time" ;;
echo "it's a thursday" ;;
echo "it's a friday" ;;
echo "it's a saturday" ;;
echo "it's a holiday time" ;;
echo "Please type days name" ;;

Run the file with bash command.


echo "Hint : 79, 85, 90"
read -p "Enter your marks : " n
case $n in
echo  echo -e "\nGot it man! you have to 90 marks in Maths" ;;
echo -e "\nHurrah! you got 79 marks in English" ;;
echo -e "\nYaa Man! you got 85 marks in Hindi" ;;
echo -e "\nSorry, try for the next time" ;;

Run the file with bash command.

I hope you liked this post, then you should not forget to share this post at all.
Thank you so much :-)



This was written for educational purpose and pentest only.
The author will not be responsible for any damage ..!
The author of this tool is not responsible for any misuse of the information.
You will not misuse the information to gain unauthorized access.
This information shall only be used to expand knowledge and not for causing  malicious or damaging attacks. Performing any hacks without written permission is illegal ..!

All video’s and tutorials are for informational and educational purposes only. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. We believe that it is impossible to defend yourself from hackers without knowing how hacking is done. The tutorials and videos provided on www.hackingtruth.in is only for those who are interested to learn about Ethical Hacking, Security, Penetration Testing and malware analysis. Hacking tutorials is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used.

All tutorials and videos have been made using our own routers, servers, websites and other resources, they do not contain any illegal activity. We do not promote, encourage, support or excite any illegal activity or hacking without written permission in general. We want to raise security awareness and inform our readers on how to prevent themselves from being a victim of hackers. If you plan to use the information for illegal purposes, please leave this website now. We cannot be held responsible for any misuse of the given information.

  - Hacking Truth by Kumar Atul Jaiswal

My Self Kumar Atul Jaiswal Urf HackerboY and Kumar Atul Jaiswal is a name among millions who struggled failed and surged ahead in search of how to become a Hacker ( passionate about Hacking just like profession an entrepreneur ), just like any middle class guy, he too had a bunch of unclear dreams and a blurred version of his goals in life 😊.


Post a Comment


Send Us A Email

Search This Blog


Contact Info

The page name itself is a call-to-action; Treat it with some respect.!


15, Ranchi, India, 834002