reading default config file in a bash script


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. deftwitlogrc="~/.twitlog.rc"
  2.  
  3. #
  4. # Parse command line
  5. #
  6.  
  7. me=`basename $0 .sh`
  8. usage="Usage: $me [-c config-file] <message> \n\nNOTE: config-file defaults to $deftwitlogrc"
  9.  
  10. while getopts ":c:" options; do
  11. case $options in
  12. c ) twitlogrc=$OPTARG;;
  13. h ) echo -e $usage
  14. exit 0;;
  15. \? ) echo -e $usage
  16. exit 1;;
  17. * ) echo -e $usage
  18. exit 1;;
  19. esac
  20. done
  21.  
  22. shift $((OPTIND - 1))
  23.  
  24. #
  25. # Try and read config file
  26. #
  27. if [ -z "$twitlogrc" ]
  28. then
  29. source ${HOME}/.twitlog.rc
  30. else
  31. source $twitlogrc
  32. fi
  33.  
  34. if [ $? -ne 0 ]
  35. then
  36. echo "Cannot open config file"
  37. echo
  38. echo -e $usage
  39.  
  40. exit 1
  41. fi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.