Advertisement
sanpai

GETOPTS EXAMPLE

Oct 19th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo " Enter the Name , Place ,Thing to Print the Same "
  4.  
  5. echo " PLEASE ENTER IN THE BELOW FORMAT TO WORK "
  6.  
  7. echo " -n[SPACE]name -p[SPACE]place -t[SPACE]thing"
  8.  
  9. if [ $# -eq 0 ]
  10.  
  11. then
  12.  
  13. echo "ENTER THE ARGUMENTS PLEASE"
  14.  
  15. fi
  16.  
  17. while getopts n:p:t: opt
  18.  
  19. do
  20.  
  21. case "$opt" in
  22.  
  23. n)na="$OPTARG";echo "The name is $na" ;;
  24. p)pa="$OPTARG";echo "The place is $pa" ;;
  25. t)ta="$OPTARG";echo "The thing is $ta" ;;
  26. *)echo "You Haven't entered anything";;
  27.  
  28. esac
  29. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement