I am converting shell script to Perl. In shell I have a code
parse_prog_args()
{
if [ $# -gt 0 ]
then
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
;;
-F* | -f* )
export _REPORT_NAME_=$2
export _REPORT_NAME_
shift
;;
-S* | -s* )
export _SRC_DIR_=$2
export _SRC_DIR_
shift
;;
-COPYONLY | -copyonly )
export _COPY_ONLY_="1"
export _COPY_ONLY_
;;
*)
echo "[$1] Argument is invalid"
echo "Usage:"
echo "\t$PROG"
echo "\t\t[-S source_directory] # provide bps batch job seq. 576 is default"
echo "\t\t[-F cool_file_name] # test extraction of price file without sending to ADP"
echo "\t\t[-P process_date] # provide bps batch job seq. 576 is default"
echo "\t\t[-COPYONLY] # provide bps batch job seq. 576 is default"
exit
;;
esac
shift
done
fi
}
parse_prog_args $@
What I don't understand is, why shell require such function call
parse_prog_args $@
What it sends to the function?
Thanks for contribution
1 Like
man ksh
yields:
Special Parameters
The shell treats several parameters specially. These parameters may only be referenced; assignment to them is
not allowed.
* Expands to the positional parameters, starting from one. When the expansion is not within double quotes,
each positional parameter expands to a separate word. In contexts where it is performed, those words are
subject to further word splitting and pathname expansion. When the expansion occurs within double
quotes, it expands to a single word with the value of each parameter separated by the first character of
the IFS special variable. That is, "$*" is equivalent to "$1c$2c...", where c is the first character of
the value of the IFS variable. If IFS is unset, the parameters are separated by spaces. If IFS is null,
the parameters are joined without intervening separators.
@ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes,
each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... If the double-
quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning
part of the original word, and the expansion of the last parameter is joined with the last part of the
original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are
removed).
Fromm your explanation we don't need this function, or we need to send clearly parameters. Please I don't have bash. it is an old system AIX and we use
#!/bin/sh
Thanks for contribution
Hmm....
your parse_prog_args
functions takes the arguments [$@] from the list past to the script at the point of a call. I don't see how you can state that we don't need this function, or we need to send clearly parameters
or what it means...
Your /bin/sh
interpreter most likely has the same functionality for $@
as bash - man sh
for details.
Now I understand. Everything what is left, to figure out, how to make it works in Perl
Thanks for contribution