What I'm sharing for you is how to use case statements to write some scripts that you choose to execute. Case statements are mainly adapted for use in some complex selection of scripts, if we use if multi-branch statements can also be written out, but obviously too shiver, at this time our best choice is the case statement.
Conditional Judgment: Case statement
Case variable reference in
PAT1)
Branch 1
;;
PAT2)
Branch 2
;;
...
*)
Default Branch
;;
Esac
Example code:
1 #!/bin/bash
2
3 #Author: Wangjun
4 #Version: 1.0
5 #Create time:2016-08-14 09:56:23
6 #Description: Casetest
7
8 echo "C=create;o=open;d=delet;m=modify"
9 Read-p "Please choose:" Choose
"$choose" in
c)
echo "Create file"
13;;
+ O)
echo "Open file"
16;;
(d)
echo "Delet file"
19;;
(m)
echo "Modify file"
22;;
23 *)
echo "Error input"
25;;
Esac
Execution effect:
650) this.width=650; "title=" Casetest.png "style=" Float:none "src=" http://s5.51cto.com/wyfs02/M02/85/EF/ Wkiol1ev6ghrnkkxaabhm5dum8u575.png "alt=" Wkiol1ev6ghrnkkxaabhm5dum8u575.png "/>
650) this.width=650; "title=" Casetest2.png "style=" Float:none "src=" http://s1.51cto.com/wyfs02/M00/85/EF/ Wkiom1ev6gldvadmaabx5pcwa8i503.png "alt=" Wkiom1ev6gldvadmaabx5pcwa8i503.png "/>
About the use of the case statement is simple to share so much, of course, all bloggers of the blogger, will be updated at any time, I hope you can look back.
This article is from the "Love Firewall" blog, be sure to keep this source http://183530300.blog.51cto.com/894387/1837755
Shell script Programming--case statements