Shell function parsing arguments, which didn't receive. Why?

I have a shell script, which has a function, which call a perl script. Also it has a shell function call parse_ars as fogllow:

#!/bin/ksh

load_ici_dat() {
cd ${OUTPUT_DIR}
typeset batch_file=XRED${MM}${DD}
typeset SCRIPT="${PROG}.pl"
echo "time ${PERLEXE5X} ${PERL_HOME}/${SCRIPT} ${ORACLE_USER} ${PROCESS_DATE}"
time ${PERLEXE5X} ${PERL_HOME}/${SCRIPT} ${ORACLE_USER} ${PROCESS_DATE}
if [ $? -ne 0 ]
then
abnormal_termination "${STEP}" "${OUTPUT_DIR}" "Fail to run ${PERL_HOME}/${S
CRIPT}"
fi
}

################################################################################
###############################
# Main Program
################################################################################
###############################
PROG=`basename $0 | awk -F. '{print($1)}'`

parse_args $@
_PROCESS_DATE_PRESET_="${PROCESS_DATE}" 

In pARSE_ARGS I HAVE:

echo "VARVAR $#"
if [ $# -gt 0 ]
then
export THREAD_ARG="$@"
while [ ! -z "$1" ]
do
case $1 in
-P* | -p* )
export PROCESS_DATE=$2
export MM=`echo $2 | cut -c5-6`
export DD=`echo $2 | cut -c7-8`
export YY=`echo $2 | cut -c3-4`
export YYYY=`echo $2 | cut -c1-4`
export PROCESS_DATE_US_MMDDYY="$MM/$DD/$YY"
shift
;;
-OUT* | -OUt* | -Out* | -out* | -oUT* | -ouT* | -oUt* )
if [ -d $2 ]
then
export OUTPUT_DIR=$2
fi
shift
;;
-IN* | -In* | -in* | -iN* )
if [ -d $2 ]
then
export INPUT_DIR=$2
fi
shift
;;
-LOG* | -LOg* | -Log* | -log* | -lOG* | -loG* | -lOg* )
if [ -d $2 ]
then
export LOG_HOME=$2
fi
shift
;;
-COO* | -COo* | -Coo* | -coo* | -cOO* | -coO* | -cOo* )
if [ -d $2 ]
then
export COOL_DIR=$2
fi
shift
;;
-CBD* | -CBd* | -Cbd* | -cbd* | -cBD* | -cbD* | -cBd* )
COOLBDAY=$2
shift
;;
-TES* | -TEs* | -Tes* | -tes* | -tES* | -teS* | -tEs* )
TEST="Y"
;;
-RELOAD* | -RESEND* | -reload* | -resend* | -Reload* | -Resend* )
RELOAD="Y"
esac

I understand, that parse_args, parsing arguments, which receive shell script, but it starts from crontab without any arguments
What arguments it is parsing?

Thanks for contribution

What operating system and shell are you using? (It looks like you're using ksh in your main script, but pARSE_ARGS doesn't specify a shell to be used when it is run.) On many systems, cron will invoke scripts using /bin/sh (not the shell you were using when you added a cron job using crontab ).

What line in crontab invokes your shell script? (You say that cron won't pass arguments to your script, but that is only true if no arguments are given to it by the crontab entry that causes cron to invoke your script.

Note that in your shell script, the two lines:

abnormal_termination "${STEP}" "${OUTPUT_DIR}" "Fail to run ${PERL_HOME}/${S
CRIPT}"

Both seem to be incomplete and look as though they should be joined together in a single line with no space between them.

Note that you say you have a file named pARSE_ARGS but your main script invokes an application named parse_args . Case distinction is important for UNIX shells (including ksh ).

Several of the patterns in your case statement seem to be missing one or more patterns. For example:

-OUT* | -OUt* | -Out* | -out* | -oUT* | -ouT* | -oUt* )

won't match words starting with -OuT . Is that intentional? Have you considered using patterns like:

-[Oo][Uu][Tt]*)

instead of:

-OUT* | -OUt* | -OuT* | -Out* | -oUT* | -oUt* | -ouT* | -out* )

They both cover all 8 case sensitive cases, but it is immediately obvious that the 1st form covers all 8 cases of three character strings while it is harder to determine that the 2nd form is not missing a pattern and does not have any duplicated patterns.

Your script invokes parse_args using:

parse_args $@

There is a HUGE difference between $@ and "$@" . You almost certainly want to use:

parse_args "$@"