How to handle scripts that expect an input

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

hi,
try using * as a separate part instead of combining it. Hope this helps.

snippet from ABS guide,

case $( arch ) in # "arch" returns machine architecture.
# Equivalent to 'uname -m' ...
i386 ) echo "80386-based machine";;
i486 ) echo "80486-based machine";;
i586 ) echo "Pentium-based machine";;
i686 ) echo "Pentium2+-based machine";;

  • ) echo "Other type of machine";;
    esac

Regards,
busyboy

Hi

I have tried this as well and it doesn't seem to work.

Can you please suggest other alternatives.

Thank you for your help.

Regards

LadyAnne

check the number of arguments

if [[ $# -eq 0 ]]; then
  display_help
  exit 1
fi