PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/datestr

https://code.google.com/p/xmeta/
Korn Shell | 69 lines | 33 code | 5 blank | 31 comment | 2 complexity | f6442f2efe9a09f509490112890e96fd MD5 | raw file
  1. #!/bin/env ksh
  2. #
  3. # Copyright (C) Young, Fey <fey.young@gmail.com>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # SCRIPT: datestr
  19. # AUTHOR: Young, Fey
  20. # DATE: 2010-8-30
  21. # REV: 1.0.P
  22. #
  23. # PURPOSE: print the current datetime in specified format
  24. #
  25. # set -n # Uncomment to check syntax without execution
  26. #
  27. # set -x # Uncomment to debug
  28. #
  29. ############################# FUNCTIONS ##################################
  30. function usage {
  31. echo "Usage: datestr [option]"
  32. echo " -s, --short YYYY-mm-dd"
  33. echo " -l, --long YYYY-mm-dd HH:MM:SS"
  34. echo " -c, --compact YYYYmmdd"
  35. echo " -d, --default YYYYmmddHHMMSS"
  36. exit 1
  37. }
  38. ################################ MAIN ####################################
  39. if (( $# > 1 ))
  40. then
  41. usage
  42. fi
  43. flag='-d'
  44. if (( $# == 1 ))
  45. then
  46. flag=$1
  47. fi
  48. case $flag in
  49. '-d')
  50. date '+%Y%m%d%H%M%S'
  51. ;;
  52. '-s')
  53. date '+%Y-%m-%d'
  54. ;;
  55. '-c')
  56. date '+%Y%m%d'
  57. ;;
  58. '-l')
  59. date '+%Y-%m-%d %H:%M:%S'
  60. ;;
  61. *)
  62. usage
  63. esac
  64. # End of script