Posted By

Mazzaroth on 02/19/11


Tagged


Versions (?)

starter


 / Published in: Bash
 

  1. #!/bin/bash
  2.  
  3. # DEFAULT VALUES
  4. default_output_format='txt'
  5. default_position_column_width=40
  6.  
  7.  
  8. # SUPPORTING FUNCTIONS
  9. function display_usage {
  10. echo "Usage: `basename $0` [-o (txt|csv)] [-wp <integer>] [-h]"
  11. echo " where"
  12. echo " -o : Specifies the output format (txt or csv). Default is '${default_output_format}'."
  13. echo " -wp : Specifies the width of the 'Position' column. Default is ${default_position_column_width}."
  14. echo " -h : Display this usage."
  15. exit
  16. }
  17.  
  18.  
  19. # ASSIGN DEFAULT VALUES
  20. position_column_width=$default_position_column_width
  21. output_format=$default_output_format
  22.  
  23.  
  24. # GET COMMAND LINE ARGUMENTS
  25. while [ $# -gt 0 ]
  26. do
  27. case $1
  28. in
  29. '-o')
  30. output_format=$2
  31. shift 2
  32. ;;
  33.  
  34. '-wp')
  35. position_column_width=$2
  36. shift 2
  37. ;;
  38.  
  39. '-h')
  40. display_usage
  41. ;;
  42.  
  43. *)
  44. echo "Error: unknown argument '$1'."
  45. display_usage
  46. ;;
  47. esac
  48. done
  49.  

Report this snippet  

You need to login to post a comment.