Results 1 to 3 of 3

Thread: Allowing arguments in a bash script

  1. #1
    Join Date
    Jun 2008
    Location
    Cleveland, TN USA
    Posts
    412

    Default Allowing arguments in a bash script

    I wrote a bash script that can do an incremental and full backup of the current users $HOME directory. it works for the most part, the one thing I can't seem to get working is to get it to accept arguments to determine if it does a full back up, incremental back up, or just print out help info. The current way I have it set up is with getopts:

    Code:
    while getopts "o:ifn" opt; do
      case "$arg" in
        o ) output="$OPTARG";  	;;
        i ) btype="incremental";	;;
        f ) btype="full";		;;
        n ) noinc=1;		;;
        ? ) usageQuit		;;
      esac
    done
    I know it does not accept "--" as valid flags, but no matter if I do "-f" or just "f" the script runs the defaulted incremental backup. If you need more of the code I will be happy to post/send it to you.

    Thank you for the time
    "We must plan for freedom, and not only for security, if for no other reason than only freedom can make security more secure." Karl Popper

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Allowing arguments in a bash script

    Code:
    while getopts "o:ifn" opt; do
      case "$opt" in
        o ) output="$OPTARG";  	;;
        i ) btype="incremental";	;;
        f ) btype="full";		;;
        n ) noinc=1;		;;
        ? ) usageQuit		;;
      esac
    done

  3. #3
    Join Date
    Jun 2008
    Location
    Cleveland, TN USA
    Posts
    412

    Default Re: Allowing arguments in a bash script

    Thanks, that was very obvious don't know why I missed it.
    "We must plan for freedom, and not only for security, if for no other reason than only freedom can make security more secure." Karl Popper

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •