Make script that run with argument if not run from configuration file argument

Hello,

Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file

i.e I am workiing on a script which will run through crontab and the script will
chekout the code ,zip and copy to the particular location.

But the script should be in this way

if someone pass the argument then it will checkout that code else if argument doesn't pass then it will take the argument from the configuration file.

Thanks

In my opinion this is more logic than script problem. You can do something like:

# Check if you have arguments to your scripts (maybe using getopts)
# If not, check and load data from configuration file
if [ ${#} -eq 1 ]
then
    zipCode=${1}
else
    # Load configuration file
    . <configuration file>
fi

I hope it helps! At least a start point for you...

Or set all the values by sourcing the configuration file and let the passed argument (if any) over-write...

#!/bin/bash

## define some functions

clr() {
rm -f ${1}* && echo 'all process are ok:)'
}

zipping() {
zipf=$(mktemp)
zip -rv9 $zipf.zip $1 ; chk $? zip $zipf
cpping $zipf.zip $2;clr $zipf
}

tgzzing() {
tgzf=$(mktemp)
tar -czf $mytgz.tgz $1 ; chk $? tgz $tgzf
cpping $mytgz.tgz $2;clr $tgzf
}

rarring() {
rarf=$(mktemp)
rar_static a $rarf.rar $1 ; chk $? rar $rarf
cpping $rarf.rar $2 ; clr rarf
}

cpping() {
cp $1 $2/${sour//\//_}_`date +%F__%H-%M-%S`.${1##*.}
[ $? -ne 0 ] && echo '$2 process is fail!!'
}

chk() {
if [ $1 -ne 0 ] ; then echo "$2 process is fail!";exit 1;fi
}

menu() {
echo -e '1-)zip&cp\n2-)tgz&cp\n3-)rar&cp'
 read -p "Please select your process ? " i
case $i in
 1)zipping $sour $targ;;
 2)tgzzing $sour $targ;;
 3)rarring $sour $targ;;
 *)echo "invalid process!! ; exiting!!";exit 1;;
esac
}

## specify conf file
conff=/home/conff

## Only first TWO parameter will be considered as source/target ##
if [ $# -eq 0 ] ; then
  echo "parametre(s) trying to take from '$conff' file";sleep 0.5
  sour=$(awk '{print $1 }' $conff);targ=$(awk '{print $2}' $conff)
  menu;
else
sour=$1;targ=$2;menu
fi