helper_functions.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. #
  3. #
  4. # This script defines some helper functions to be used in
  5. # other scripts so as to not have to define them every time
  6. # they are used.
  7. #
  8. #
  9. ############################################################
  10. # make echo more portable
  11. #
  12. #
  13. echo_print() {
  14. #IFS=" " command
  15. eval 'printf "%b\n" "$*"'
  16. }
  17. echo_n_print()
  18. {
  19. eval 'printf "%b" "$*"'
  20. }
  21. ############################################################
  22. #
  23. # expand debug output
  24. #
  25. echo_debug() {
  26. if [ "$DEBUG" = "true" ] ; then
  27. $ECHO "$*"
  28. $ECHO "$*" >> $DEBUG_FILE
  29. fi
  30. }
  31. ############################################################
  32. #
  33. # time stamp
  34. #
  35. setTime() {
  36. # set time
  37. NOW="`date '+%m/%d/%Y %H:%M %Z'`"
  38. }
  39. setAlias() {
  40. unalias -a
  41. cmd_list="printf
  42. touch
  43. cat
  44. more
  45. grep
  46. egrep
  47. cut
  48. find
  49. uname
  50. awk
  51. sed
  52. sort
  53. uniq
  54. expr
  55. cksum
  56. ps
  57. rm
  58. ls
  59. "
  60. path_list="/bin/
  61. /usr/bin/"
  62. for c in $cmd_list
  63. do
  64. alias_flag=0
  65. for p in $path_list
  66. do
  67. if [ -x ${p}${c} ];
  68. then
  69. alias ${c}=${p}${c}
  70. alias_flag=1
  71. break
  72. fi
  73. done
  74. if [ $alias_flag -eq 0 ] ; then
  75. if [ "${alias_not_found}" = "" ]; then
  76. alias_not_found=$c
  77. else
  78. alias_not_found=${alias_not_found},$c
  79. fi
  80. fi
  81. done
  82. if [ "${alias_not_found}" != "" ]; then
  83. eval 'printf "${alias_not_found} utility(ies) not found. Please contact your assigned consultant"'
  84. exit 600
  85. fi
  86. #alias
  87. }
  88. ECHO="echo_print"
  89. ECHON="echo_n_print"