[/bin/sh] passing parameters with quotes between 2 scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [/bin/sh] passing parameters with quotes between 2 scripts
# 1  
Old 07-25-2008
Question [/bin/sh] passing parameters with quotes between 2 scripts

Hi,

I have a first shell script (/bin/sh) that receives some paremeters. This is only an example (there are more parameters in fact and this one is among them):
-header "This is a test"
This script calls a secund shell script (/bin/sh) with the same parameters. But, quotes disappear as I would expect it unluckily... Smilie
This is the first script:
Code:
#!/bin/sh
 echo "mytest.sh"
 parameters=$@
 while [ $# != 0 ] ; do
     echo $1
     shift
 done
 ./mytest2.sh ${parameters}
 exit 0

This is the secund script:
Code:
#!/bin/sh
echo "mytest2.sh"
while [ $# != 0 ] ; do
    echo $1
    shift
done
exit 0

The result is:
Code:
{velo_love}69: ./mytest.sh -header "This is a test"
mytest.sh:
-header
This is a test
mytest2.sh:
-header
This
is
a
test

So, how to pass the parameter between quotes from the first script to the second one? Any tips?

Best regards,


[EDIT]
Ok, I think I have found something interesting. If I change my first script into this
Code:
#!/bin/sh
echo "mytest.sh:"
./mytest2.sh ${1+"$@"}
exit 0

Then all parameters are correctly passed between the two scripts:
Code:
{velo_love}239: ./mytest.sh -header "This is a test"
mytest.sh:
-header
This is a test
mytest2.sh:
-header
This is a test


Last edited by velo_love; 07-25-2008 at 06:18 AM.. Reason: Got a solution!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing parameters with spaces between scripts

I have 2 scripts. test.sh, which calls submit2.sh. One of the parameters contains space and is quoted. ((((./submit2.sh Group_1_2_AMS_DAILY_CORE_GRP03 AMS AMS_D 'DAILY REPORT PROCEDURES'; echo $?>&3) | tee 1.log >&4)3>&1) | (read xs; exit $xs)) 4>&1 echo parm 1 = $1 echo parm 2 = $2... (1 Reply)
Discussion started by: andyclam
1 Replies

2. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

3. Shell Programming and Scripting

Passing Parameters to Crontab

Hello Experts, I have a requirement to pass some parameters to Linux cron tab. For ex: My default cron entry looks like this as below: ------------------------------- 55 10 * * --... (7 Replies)
Discussion started by: MaheshChaudhari
7 Replies

4. Shell Programming and Scripting

Passing single quotes to grep

Hi, I have a grep command which searches if a particular word ends in a pattern grep 'ee\>' * The above command searches for any word that ends with ee across files and works as expected. I need to parametrize ee and run the command so I tried the following but none work A=ee grep... (1 Reply)
Discussion started by: wahi80
1 Replies

5. Shell Programming and Scripting

Passing 2+ parameters to one command

I have a script that uses more than one parameter. It looks like this: for i in `cat /tmp/listofpolicies`; do for x in $(cat /tmp/lst |sed 's/^/\/usr\/openv\/netbackup\/db\/class\//g'); do /usr/openv/netbackup/bin/admincmd/bpplinclude $i -delete -f $x;done;done The problem is that the... (3 Replies)
Discussion started by: newbie2010
3 Replies

6. Shell Programming and Scripting

passing parameters to the script

how can i make a script to run only when parameters are given, if parameters are not given it should through an error , saying "please enter a parameter" for ex: i want a find command to run only when the parameters are given (4 Replies)
Discussion started by: knip
4 Replies

7. UNIX for Dummies Questions & Answers

Passing the parameters through a file

Hi All, I have written a shell script and the script is working fine, I am passing my MIT_ID(NUMBER VALUE) to the shell script from the command prompt and my script is executing as expected. Now I have to pass all the MIT_ID's from a .txt file to the shell script,as I am automating this I... (6 Replies)
Discussion started by: gaur.deepti
6 Replies

8. Shell Programming and Scripting

Passing parameter in quotes

Hi, PW='/as sysdba'; export PW in other module I call sqlplus ${PW} (this line I unable to change!) How I can define PW so that sqlplus calls PW in quotes i.e sqlplus '/as sysdba' I tried like this PW="'/as sysdba'"; export PW - no luck Thanks in advance (2 Replies)
Discussion started by: zam
2 Replies

9. Shell Programming and Scripting

passing more than 9 parameters

hi, i am passing around 14 parameters for a script a=$1 b=$2 c=$3 d=$4 e=$5 f=$6 g=$7 h=$8 i=\"${9}\" shift j=\"${1}\" still for j it is displaying the 1st parameter value..how to make it take the 10th parameter (2 Replies)
Discussion started by: dnat
2 Replies

10. Shell Programming and Scripting

Using #! /bin/sh in Shell scripts

Hi All, What does #! /bin/sh mean in a shell script? Is it mandatory to include in a shell script? I'm able to execute the shell script without it. Any help on this would be appreciated. (4 Replies)
Discussion started by: sumesh.abraham
4 Replies
Login or Register to Ask a Question