Strange function call in the shell script parse_prog_args $@


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange function call in the shell script parse_prog_args $@
# 1  
Old 04-25-2017
Strange function call in the shell script parse_prog_args $@

I am converting shell script to Perl. In shell I have a code
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
Code:
 parse_prog_args $@

What it sends to the function?

Thanks for contribution
This User Gave Thanks to digioleg54 For This Post:
# 2  
Old 04-25-2017
man ksh yields:
Code:
   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).

# 3  
Old 04-25-2017
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
Code:
 #!/bin/sh

Thanks for contribution
# 4  
Old 04-25-2017
Quote:
Originally Posted by digioleg54
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
Code:
 #!/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.
# 5  
Old 04-25-2017
Now I understand. Everything what is left, to figure out, how to make it works in Perl


Thanks for contribution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strange third argument in shell function

In one of my shell function I found the following set_default_values () { prog=$1 PROC_DT=$2 RESET_ALL="${3-N}" #echo "Processing date as passed = , Program name = " ...... I understand the first and second arguments, but don't understand... (1 Reply)
Discussion started by: digioleg54
1 Replies

2. Programming

Writing a UNIX shell script to call a C function and redirecting data to a .txt file

Hi, I am complete new to C programming and shell scripting. I just wrote a simple C code to calculate integral using trapezoid rule. I am prompting user to pass me No. of equally spaced points , N , upper and lower limit. My code looks as follows so far: #include<stdio.h> #include<string.h>... (2 Replies)
Discussion started by: bjhjh
2 Replies

3. 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

4. Shell Programming and Scripting

Segmentation fault in function call, shell script

I am getting Segmentation fault at below function call in my script: get_x() { sqlplus -s / <<end | grep KEEP | sed 's/KEEP//;s///g' select 'KEEP' ,table_name from all_synonyms where upper(synonym_name)= '$1'; exit end x=$(get_x $1) echo " SQL OUTPUT IS :: $x" } I am getting output of... (1 Reply)
Discussion started by: IB_88
1 Replies

5. Shell Programming and Scripting

Call a function in shell script from another shell script

I've 2 shell scripts viz., CmnFuncs.ksh and myScript.ksh. 1st script contains all common functions and its code is as below: $vi CmnFuncs.ksh #!/bin/ksh RunDate() { .... .... export Rundt=`date +%Y%m%d` } 2nd script is invoking the above one and I expect to use the RunDt variable... (8 Replies)
Discussion started by: njny
8 Replies

6. Shell Programming and Scripting

Call shell script function from awk script

hi everyone i am trying to do this bash> cat abc.sh deepak() { echo Deepak } deepak bash>./abc.sh Deepak so it is giving me write simply i created a func and it worked now i modified it like this way bash> cat abc.sh (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

7. Red Hat

how to call a particular function from one shell another shell script

please help me in this script shell script :1 *********** >cat file1.sh #!/bin/bash echo "this is first file" function var() { a=10 b=11 } function var_1() { c=12 d=13 (2 Replies)
Discussion started by: ponmuthu
2 Replies

8. Shell Programming and Scripting

Shell Script to call another function

Here is the following code : 1. # gcc -c test firstprog.c the above command will generate a executable file called "test " in which ever directory it is run. Assuming It will also return a value. 2. In the below SCRIPT . test is a file generated by compiling a c program... (3 Replies)
Discussion started by: Vabiosis
3 Replies

9. Shell Programming and Scripting

how can i call a function in shell script

i have a function written in one shell script and i want to call that function in another shell script and use the value returned by that script. can any one suggest me how can i do that? regards, Rajesh.P (4 Replies)
Discussion started by: rajesh.P
4 Replies

10. Shell Programming and Scripting

i want to call a oracle function in my shell script

i want to call a oracle function in my shell script (4 Replies)
Discussion started by: dineshr85
4 Replies
Login or Register to Ask a Question