Handling values with space while passing commandline argument from wrapper script in KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Handling values with space while passing commandline argument from wrapper script in KSH
# 1  
Old 10-23-2009
Handling values with space while passing commandline argument from wrapper script in KSH

Hi there,

I have a wapper script which passes the argument from command prompt to inner script.. It works fine as long as the argument containing single word. But when value contains multiple word with space, not working as expected. I tried my best, couldn't find the reason. Gurus, pls. help me.

Code:
Here is the code snippet :

Wrapper.sh

#### Wrapper Begin #####
while getopts ":i:" OPTION 2>/dev/null
  do
     case "$OPTION" in
          i) inargI=$OPTARG;;
         \?) print "Usage: $0 -i <ini>"
             exit -1 ;;
      esac
done
echo "$inargI"
$inargI
#### Wrapper End #####


inner.sh

#### Inner Begin ####
while getopts ":i:j:" OPTION 2>/dev/null
  do
     case "$OPTION" in
          i) inargI=$OPTARG;;
          j) inargJ=$OPTARG;;
         \?) print "Usage: $0 -i <job.ini> -j <job2.ini>"
             exit -1 ;;
      esac
done
echo "i=$inargI"
echo "j=$inargJ"
#### Inner End ####

When I run the arguments with out space, it works fine.

$ wrapper.sh -i "inner.sh -i \"Macain\" -j \"Obama\" "
inner.sh -i "Macain" -j "Obama" 
i="Macain"
j="Obama"


But When I run with space , the results are not showing as expected.

$ wrapper.sh -i "inner.sh -i \"John Macain\" -j \"Barack Obama\" "
inner.sh -i "John Macain" -j "Barack Obama" 
i="John
j=


The expected result should be
i="John Macain"
j="Barack Obama"

Appreciate your help.

Thanks & Regards,
Kans.

Last edited by kans; 10-23-2009 at 06:18 PM.. Reason: Moved the code into code space
# 2  
Old 10-23-2009
Quote:
Originally Posted by kans
Hi there,

I have a wapper script which passes the argument from command prompt to inner script.. It works fine as long as the argument containing single word. But when value contains multiple word with space, not working as expected. I tried my best, couldn't find the reason. Gurus, pls. help me.

Here is the code snippet :

Wrapper.sh

Please wrap code in [code] ... [/code] tags.
Quote:
Code:
#### Wrapper Begin #####
while getopts ":i:" OPTION 2>/dev/null
  do
     case "$OPTION" in
          i) inargI=$OPTARG;;
         \?) print "Usage: $0 -i <ini>"
             exit -1 ;;
      esac
done
echo "$inargI"
$inargI


Code:
eval "$inargI"

# 3  
Old 10-23-2009
Hi cfajohnson,

Thanks a lot. It works. I will test with actual code and will come to you, if I face any issues on it... Thanks again for the prompt response. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue handling single quoted argument in shell script.

Below is my script that works fine and prints the desired output: #!/bin/ksh echo "$1" | while IFS= read -r dirpath do echo "DIRR_PATH:$dirpath" install_dir=$install_dir" "$dirpath done echo "Desired Output:$install_dir" Output: ./loopissue.sh... (10 Replies)
Discussion started by: mohtashims
10 Replies

2. Shell Programming and Scripting

sed commands success / fail from commandline vs ksh script

solaris 5.10 Generic_138888-03 sun4v sparc SUNW,Sun-Fire-T200 I need a sed command that tests true when presented with lines that contain either forward and backslash. input file: c:/myFile.txt c:\yourFile.txt It doesn't appear that sed (in my environment anyway) supports... (4 Replies)
Discussion started by: msutfin
4 Replies

3. Shell Programming and Scripting

Help with Handling multiple argument in shell script

Hi i have written a shell script that takes only single ip address from the user and calculates its latency and reliability, can you please tell me that what should be done if i want that user should enter 100 or 1000 ip address (5 Replies)
Discussion started by: Preeti_17
5 Replies

4. Shell Programming and Scripting

passing argument in script?

hi, I want to implement some function to perform following task if ; then $TEXT = "Data_0" else $TEXT = $1 fi if ; then $Lines = 45 else $Lines = $2 fi Kindly suggest, thanks (11 Replies)
Discussion started by: nrjrasaxena
11 Replies

5. Shell Programming and Scripting

Wrapper script Oracle look KSH

I have a KSH script that I want to call in a loop for each row in the above table --- new_script.ksh (psuedo code) the contents on this new script would be something like below... for t in (select table_name,schema_name from laod_table) loop /bin/load_table.ksh t.table_name... (4 Replies)
Discussion started by: vr23
4 Replies

6. Shell Programming and Scripting

Validating commandline argument

Hi, I am calling a script script2.shl from script1.shl as below script2.shl "TABLE_NAME" -r 10 In that I have to validate the parameter 4. i.e : it should be only 10 20 30 40 50 I know that I can do it by checking like below if ]; then echo "TRUE" else echo "FALSE" fi ... (3 Replies)
Discussion started by: mr_manii
3 Replies

7. Shell Programming and Scripting

Passing commandline argument to a function

Hi, I have 2 ksh scripts. Script1.ksh contains function definition. script1.ksh function f1() { while getopts a:c: args do case $args in a) ARG1=$OPTARG ;; c) ARG2=$OPTARG ;; \?) echo "Error no valid Arguments passed" esac done echo $ARG1 echo $ARG2 script2.sh (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

8. Shell Programming and Scripting

passing values to function in Ksh

Hi, I'm trying to work on the script given below #!/bin/ksh -x pfile() { echo "$1" } touch smp19 echo "Hi" > smp19 result=$(pfile $smp19) echo $result As highlighted , when i pass $smp19 as parameter ,it does not display the output.However when i try giving "Hi" instead... (2 Replies)
Discussion started by: Sheema
2 Replies

9. Shell Programming and Scripting

New wrapper script will be developed to wrap two ksh scripts

Hi friend,:) The script should invoke these scripts sequentially! When one will finish the second will start. Please help me with it, thanks,:b: Ishai (3 Replies)
Discussion started by: ishai82
3 Replies

10. Shell Programming and Scripting

Passing argument from one script to other

Dear All, I have one script which accepts database name and user_id from the user, i have another script that will unload the data from all the tables based on the user_id accepted by the user. How can i pass the user_id from the 1st script to the other. My OS is sun solaris. Thanks in... (3 Replies)
Discussion started by: lloydnwo
3 Replies
Login or Register to Ask a Question