Example of a bash case statement.
Sharing a bash shell code is helpful in understanding the use of case statements by students who learn about bash.
Example:
Copy Code code as follows:
#!/bin/bash
##
# program:
# File operation
# 1.) Open file 2.) Display file 3.) Edit file 4.) Delete file
# Site:WWW.JB51.NET
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
Export PATH
echo "---------------------------------"
echo "List of item to operate file-"
echo "---------------------------------"
echo "1). Open a file-"
echo "2). Display a file-"
echo "3). Edit a file-"
echo "4). Delete a file-"
echo "---------------------------------"
Read Select
Case $select in
1)
echo "Do Open file operation"
2)
echo "Do display a file operation"
3)
echo "Do edit a file operation"
4)
echo "Do delete a file operation"
*)
echo "There is no to do!"
Exit 1
Esac