Hi
I would like to know how to handle my script that expects an input when calling the script and the user doesn't enter anything, I need to re-direct to my helpfile.
Bascically here is my script:
#!/bin/bash
csvdir="/var/local/dsx/csv/general"
csvfile="$csvdir/$csvfile"
dsxdir="/var/local/dsx/import"
dsxfile="$dsxdir/$dsxfile"
function displayHelp()
{
echo ""
echo " Usage: ./Import_PlannedCELL.sh [ -c -d ]"
echo ""
echo " -c, --csvfile identified by the input file in csv format "
echo " -d, --dsxfile identified by the output file in dsx format "
echo " -h, --help identified by the help menu "
echo ""
}
while getopts " c: d: h " option
do
case $option in
c ) csvfile="$OPTARG";;
d ) dsxfile="$OPTARG";;
h | ? | * ) displayHelp;exit;;
esac;
done
cat $csvdir/$csvfile | csvdsx -ePlanned \
-iCell:CELLID \
-cCells%BTS:SITEID^Cell:CELLID \
-sCell:CELLID \
-xCELLID,SITEID \
->$dsxdir/$dsxfile
if the user enters :
./script
instead of :
./script -h
how can i call my help function
I though this will help:
h | ? | * ) displayHelp;exit;;
but it only calls the help if I enter anything other than the specified getops options.
I need it to work also for whitespaces.
This is what I get when I try without a character:
$ ./import.sh
Warning: program compiled against libxml 207 using older 206
I/O warning : failed to load external entity "/var/local/dsx/import//var/local/dsx/import/"
failed to parse new file /var/local/dsx/import//var/local/dsx/import/
It is reading the file anyway
Thank you kindly for your help