tampurus

1 switch case

Dec 6th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. # Number indentity
  2. echo enter num
  3. read x
  4. case $x in
  5. 1) echo one
  6.     ;;
  7. 2) echo two
  8.     ;;
  9. 3) echo three
  10.     ;;
  11. *)  echo default
  12.     ;;
  13. esac
  14.  
  15. #output
  16. enter num
  17. 2
  18. two
  19.  
  20.  
  21.  
  22. # Range based
  23. echo enter any character
  24. read x
  25. case $x in
  26. [a-z]) echo chotta alphabet
  27.     ;;
  28. [A-Z]) echo bda alphabet
  29.     ;;
  30. [0-9]) echo single digit number
  31.     ;;
  32. [0-9][0-9]) echo double digit number
  33.     ;;
  34. *)  echo default
  35.     ;;
  36. esac
  37.  
  38. # Output
  39. enter any character
  40. 55
  41. double digit number
  42.  
  43. # string base
  44. echo enter any word
  45. read x
  46. case $x in
  47. 'svim') echo clg
  48.     ;;
  49. 'suresh') echo my love
  50.     ;;
  51. 'bca') echo kr rha hu
  52.     ;;
  53. 'ramesh') echo suresh alternative
  54.     ;;
  55. *)  echo match nhi hua hai defaulth hai
  56.     ;;
  57. esac
  58.  
  59. # Output
  60. enter any word
  61. suresh
  62. my love
Advertisement
Add Comment
Please, Sign In to add comment