1

I trying to make control statement to check on a option flag is used or not? For -o output.file if is used I would like to make equal to variable OUTPUTSUM = OUTPUTFILE and if there no -o option use then I have it defaulted to relative path of the script? I just not sure how to go about checking for -o option?

PSEUDO code

while getopts i:o:h OPTION
do
     case $OPTION in
         i)
             INPUTFILE=$OPTARG
             ;;
     o)
         OUTPUTFILE=$OPTARG
             ;;
         h)
             usage
         exit 1
             ;;
         ?)
             usage
             exit
             ;;
     esac
done

if [-o EXIST]; then

    OUTPUTSUM = OUTPUTFILE
else
   OUTPUTSUM = $SCRIPTPATH/SUMMARY
fi
  • Bash doesn't have a -o output.file option... – Graeme Feb 26 '14 at 20:37
  • I code it. I will add the code. – MAXGEN Feb 26 '14 at 20:42
  • Don't cross post questions, please. I deleted the one on Super User. – slhck Feb 26 '14 at 20:49
  • Using the shell for more than trivial(ish) scripts is for masochists (or SysVinit lovers). Learn a more featureful scripting language (Python, Perl, Ruby) if you regularly find yourself writing scripts. – vonbrand Feb 27 '14 at 1:43
  • What inhibits shell from being featureful language? Not enough community support? – MAXGEN Feb 27 '14 at 1:51
3

bash parameter expansion: use default value if variable is unset or null:

outputsum=${outputfile:-"$scriptpath/SUMMARY"}

Get out of the habit of using $ALL_CAPS_VARNAMES -- one day you'll use "PATH" and break your script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.