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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell function parsing arguments, which didn't receive. Why?
# 1  
Old 10-27-2017
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:
Code:
#!/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:

Code:
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
# 2  
Old 10-28-2017
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:
Code:
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:
Code:
-OUT* | -OUt* | -Out* | -out* | -oUT* | -ouT* | -oUt* )

won't match words starting with -OuT. Is that intentional? Have you considered using patterns like:
Code:
-[Oo][Uu][Tt]*)

instead of:
Code:
-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:
Code:
parse_args $@

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh parsing arguments in a string rather than from the cmdln

Hi. I have a piece of code that reads and parses command line options. I'd like to alter it slightly to read from a string (that's set elsewhere in the script) rather than directly from the command line (arg). Can somebody show me how to do this? Many thanks. My code is as follows: typeset... (6 Replies)
Discussion started by: user052009
6 Replies

2. Shell Programming and Scripting

How to call Oracle function with multiple arguments from shell script?

Dear All, I want to know how can i call oracle function from shell script code . My oracle function have around 5 input parameters and one return value. for name in *.csv; do echo "connecting to DB and start processing '$name' file at " echo "csv file name=$x" sqlplus -s scoot/tiger <!... (2 Replies)
Discussion started by: Balraj
2 Replies

3. Shell Programming and Scripting

Parsing Command Line Arguments In C shell script

]I have a string like "/abc/cmind/def/pq/IC.2.4.6_main.64b/lnx86" and this string is given by user. But in this string instead of 64b user may passed 32 b an i need to parse this string and check wether its is 32b or 64 b and according to it i want to set appropriate flags. How will i do this... (11 Replies)
Discussion started by: codecatcher
11 Replies

4. Programming

Parsing command line arguments in Python

Hi, I've a python script called aaa.py and passing an command line option " -a" to the script like, ./aaa.py -a & Inside the script if the -a option is given I do some operation if not something else. code looks like ./aaa.py -a . . if options.a ---some operation--- if not options.a... (1 Reply)
Discussion started by: testin
1 Replies

5. Shell Programming and Scripting

Need help with parsing the arguments using getopts !!

Hi all, I am trying to use long arguments for my existing script. right now my script would work if given <script_name> -t <arg1> -b <arg2> -v <arg3>. The script code is shown below. while getopts t:v:b: OPT;do case "$OPT" in t) Todo=$OPTARG;; b) Batch=$OPTARG;; ... (3 Replies)
Discussion started by: SSSB
3 Replies

6. Shell Programming and Scripting

Parsing Comma separated Arguments

Hi unix guru's I want to execute a shell script like ksh printdetails.ksh Andy,Bob,Daisy,Johnson like passing all the four names in the as the arguments and these arguments are varies between 1 to 10. How to pass these names to the shell script variable. and also i want to know the count... (4 Replies)
Discussion started by: Reddy482
4 Replies

7. Shell Programming and Scripting

Help parsing command line arguments in bash

Looking for a little help parsing some command line arguments in a bash script I am working on, this is probably fairly basic to most, but I do not have much experience with it. At the command line, when the script is run, I need to make sure the argument passed is a file, it exists in the... (3 Replies)
Discussion started by: Breakology
3 Replies

8. Shell Programming and Scripting

no of arguments to function in shell script

Hi, I have a function in shell script fun1{ echo "No.of arguments are..."} this function will be called in same script by passing arguments fun 1 2 3 I want to check the no. of arguments passed to fun1 function in the same functionbefore validation. can any one suggest me. (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

9. Shell Programming and Scripting

How to pass arguments to a function in a shell script?

Hi, I have two shell variables $t1 and $t2 which I need to pass to a function in a shell script. The function will do some computation with those two variables and echo the resultant. But I do not know how to pass teh arguments. The function written is f1() {...... ........ } What should... (3 Replies)
Discussion started by: preetikate
3 Replies

10. UNIX for Advanced & Expert Users

Parsing the command line arguments

Is there a way to get the command line arguments. I am using getopt(3) but if the arguments are more than one for a particular option than it just ignores the second argument. For eg ./a.out -x abc def now abd will be got with -x using getopt "( x : )" and string abc\0def will get stored... (7 Replies)
Discussion started by: jayakhanna
7 Replies
Login or Register to Ask a Question