Results 1 to 5 of 5
I'm having a heckuva figuring this out... I know it's got to be easy, but I'm stumped...
To make this simple, I need to return all parameters passed to a ...
- 06-04-2007 #1Just Joined!
- Join Date
- Feb 2007
- Location
- Collierville, TN
- Posts
- 7
Redirecting double-quoted string parameters
I'm having a heckuva figuring this out... I know it's got to be easy, but I'm stumped...
To make this simple, I need to return all parameters passed to a script EXACTLY how they were passed...
I wouldn't think it would be this difficult, but if a parameter is a double-quoted string, I can only seem to return the string value without the quotes...
I know I can pass \"yadayada\" and get the quotes, but that is not an option for what I'm trying to do.
Now, for the long story...
We are adding a new host - on this host we want to use scripts that are already available to call a binary on another host (without changing the scripts)... AND the binary can't be ran on the new host.
My idea was to add a script on the new host with the same name as the binary, capture all the parameters passed to it, then use ssh and pass those parameters to the binary on the old host.
If I can get past these string parameters, it will work...
Ideas?
- 06-08-2007 #2Just Joined!
- Join Date
- Feb 2007
- Location
- Collierville, TN
- Posts
- 7
With the plethora of responses to choose from, I'm guessing this is more difficult than I expected.
Turns out that only the LAST argument to the binary needs the double-quotes, so I ended up adding ifs for up to 9 parameters.
When the current parameter number equals the total parameters ($#) I concatenate a \" to the beginning and the end...
I would still like to figure out how the get the FULL argument from the command line, but I just can't see any way to do it...
Even ps doesn't show the quotes... go figure...
For what it's worth, this is where I ended up:
#!/bin/bash
if [ $# -eq 1 ]; then
arg1=\"$1\";
else
arg1=$1;
fi;
if [ $# -eq 2 ]; then
arg2=\"$2\";
else
arg2=$2;
fi;
if [ $# -eq 3 ]; then
arg3=\"$3\";
else
arg3=$3;
fi;
if [ $# -eq 4 ]; then
arg4=\"$4\";
else
arg4=$4;
fi;
if [ $# -eq 5 ]; then
arg5=\"$5\";
else
arg5=$5;
fi;
if [ $# -eq 6 ]; then
arg6=\"$6\";
else
arg6=$6;
fi;
if [ $# -eq 7 ]; then
arg7=\"$7\";
else
arg7=$7;
fi;
if [ $# -eq 8 ]; then
arg8=\"$8\";
else
arg8=$8;
fi;
if [ $# -eq 9 ]; then
arg9=\"$9\";
else
arg9=$9;
fi;
cmd1="/usr/bin/ssh <host-name> -l <user-name> "
cmd2=". <binary-path-name> $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 "
cmd=$cmd1$cmd2
cmdresult=`$cmd`
- 06-08-2007 #3Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try to set the parameters within single quotes like this:
RegardsCode:'"$1"'
- 06-08-2007 #4Just Joined!
- Join Date
- Feb 2007
- Location
- Collierville, TN
- Posts
- 7
That doesn't return the value of $1, just "$1"... am I miunderstanding something?
- 06-09-2007 #5Linux User
- Join Date
- Jun 2007
- Posts
- 318
No, single quotes means pass the string as is. The shell will not expand the parameters
Vic


Reply With Quote