Sponsored Content
Top Forums Shell Programming and Scripting Passing parameter filled variable to a script. Post 302863321 by Devyn on Sunday 13th of October 2013 08:48:54 PM
Old 10-13-2013
Passing parameter filled variable to a script.

Say I have something like this to try and build a parameter string:

Code:
OPT1="This is my Option";
OPT2="/folder/file";

PARMS="-u me -J \"$OPT1\" -g \"$OPT2\"";

./script.ksh -n 1 $PARMS;
./script.ksh -n 2 $PARMS;
./script.ksh -n 3 $PARMS;
./script.ksh -n 4 $PARMS;

But this doesn't work. For example, it just sees "This" passed instead of the whole string. Parameters without spaces seem fine. Is there anyway to do so? Tried ' and { and combinations of but no luck. Can't seem to pass the whole string in. Here's how it looks (' "This ' is printed but not the whole string):

Code:
# ./dummy.ksh
NARG=|1|
UARG=|me|
GARG=||
JARG=|"This|

NARG=|2|
UARG=|me|
GARG=||
JARG=|"This|

NARG=|3|
UARG=|me|
GARG=||
JARG=|"This|

NARG=|4|
UARG=|me|
GARG=||
JARG=|"This|

# cat script.ksh
#!/usr/bin/ksh


while getopts n:u:g:J: option; do
        case ${option} in
                n)      NARG="$OPTARG"
                        ;;
                u)      UARG="$OPTARG"
                        ;;
                g)      GARG="$OPTARG"
                        ;;
                J)      JARG="$OPTARG"
                        ;;
                [?])    print >&2 "Good Luck!";
                        exit 1
                        ;;
                esac
done


print "NARG=|$NARG|";
print "UARG=|$UARG|";
print "GARG=|$GARG|";
print "JARG=|$JARG|";
print;
# cat dummy.ksh
#!/usr/bin/ksh

OPT1="This is my Option";
OPT2="/folder/file";

PARMS="-u me -J \"$OPT1\" -g \"$OPT2\"";

./script.ksh -n 1 $PARMS;
./script.ksh -n 2 $PARMS;
./script.ksh -n 3 $PARMS;
./script.ksh -n 4 $PARMS;

#

Passing directly works fine, but not through a parameter of flags.

Cheers,
DH

Last edited by Devyn; 10-13-2013 at 10:12 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing Date as parameter with sh script

Hi I need to pass a date argument with my shell script. Can any one send me code for the same. eg For 15th Aug 2006. Iwant to pass parameter like this ./startenv.sh 08/15/2006. Everyday date argument must change. Will the below code work ? ./startenv.sh date '+%m/%d/%y' THanks... (1 Reply)
Discussion started by: pankajkrmishra
1 Replies

2. Shell Programming and Scripting

Passing a parameter while calling a script

Hello everyone I was asked to pass a parameter in the calling of a script. IŽll have two parameters London and Birmingham and IŽll need to pass this because each of these will have a specific script however with the same name. /home/script/loaddata.ksh Lond /home/script/loaddata.ksh Birm... (2 Replies)
Discussion started by: Rafael.Buria
2 Replies

3. Shell Programming and Scripting

Passing Filename as a Parameter to Another script

Hi, I have a requirement to write a script file(script1.sh) to read the file from the folder say /usr1/profiles/active and pass the file name as a parameter to another script file say (script2.sh) which would subsitute this parameter. The script2.sh will have a line like the one below ... (1 Reply)
Discussion started by: ravisg
1 Replies

4. Shell Programming and Scripting

Passing parameter from one file to shell script

Hi All, I have a 2 files. File1 i am generating using an ETL tool, which is a comman seperated delimited file which contains country code & load date. everytime, this country code will be updated from a table. It might be AB or BA & ld_date will be for which date we need to load the file. ... (7 Replies)
Discussion started by: Amit.Sagpariya
7 Replies

5. Shell Programming and Scripting

Issue in passing a parameter value from one script to another

Hi Experts, I am passing current month & day (i.e. 'Jul 21') from script aaa.ksh to zzz.ksh. The value 'Mon DD' is being used in zzz.ksh. Problem: If I pass 'Mon DD' value manually to zzz.ksh i.e. /test/zzz.ksh 'Jul 21' it works fine. However, if I pass value from aaa.ksh, it does... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

6. AIX

Passing a parameter to a shell script?

I would like to run a compress script on files in certain directories. My compress_script.sh is just basically compress file* In order for me to use this I have to copy it into each directory and run it. How can I state the directory on the command line with the compress script so it... (2 Replies)
Discussion started by: NycUnxer
2 Replies

7. Shell Programming and Scripting

Passing Parameter containing space in between to Shell Script

Hi, I have one shell script which use two parameter however one of its parameter have space in between. eg. a.sh 20110114 b c d here b c d is one parameter I used 'b c d' but its not giving correct result. Also i tried b\c\d but this one also didnt work. Any help would be... (5 Replies)
Discussion started by: diehard
5 Replies

8. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

9. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

10. UNIX for Beginners Questions & Answers

Passing output parameter(Oracle) to variable in ksh Script

Hello, I have researched and tried many way to pass OUT parameter to be stored in variable in KSH Script.Still not success, please help. Here is my Store Procedure. create procedure testout3(v_in varchar2,v_out OUT integer) as begin v_out := 1; end; Here is my testvout.ksh #!/bin/ksh... (1 Reply)
Discussion started by: palita2601
1 Replies
build-lives-rfx-plugin-multi(1) 			      General Commands Manual				   build-lives-rfx-plugin-multi(1)

NAME
build-lives-rfx-plugin-multi - builds rendered effects for LiVES SYNOPSIS
build-lives-rfx-plugin-multi type [scripts_dir exec_dir] [build_bindir] DESCRIPTION
This perl script builds rendered effects (RFX) plugins for LiVES. If scripts_dir is not defined then type is used to locate the plugin scripts directory and output directory. Type can be builtin (the default), custom, test, or builtinx. The type builtinx forces scripts_dir and exec_dir to be read from parameters and is used during LiVES install, and is the only type which should be used if scripts_dir is specified. Each plugin script in input directory is scanned to find its language code. The script is then passed to the script compiler for that lan- guage. The directory location of the script_compiler may be specified by the build_bindir parameter (as is the case during LiVES installa- tion0; otherwise the user's $PATH will be searched. Return values the script returns the following values 0 - success 1 - the "type" parameter was not defined, or set to an invalid value 3 - the builder for a plugin script was not found SEE ALSO
build-lives-rfx-plugin(1), lives(1) AUTHOR
Gabriel Finch a.k.a Salsaman (salsaman@xs4all.nl) May 9 2010 build-lives-rfx-plugin-multi(1)
All times are GMT -4. The time now is 12:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy