Operating System - Linux
1753361 Members
5478 Online
108792 Solutions
New Discussion юеВ

Re: Pass a parameter that contains a dollar sign

 
SOLVED
Go to solution
OldSchool
Honored Contributor

Re: Pass a parameter that contains a dollar sign

or you can run it thru sed,

echo "12345.k" | /usr/lbin/makekey | sed s/\\$/\\\\$/g
TimButler
New Member

Re: Pass a parameter that contains a dollar sign

This thread's a bit old, but the right
solution is vastly simpler than all of the
other suggestions.

When the first script calls the second,
it need only place the encrypted string in
single quotes. This will prevent any attempt
to interpret the argument as a shell variable.

tim
A. Clay Stephenson
Acclaimed Contributor

Re: Pass a parameter that contains a dollar sign

Well Tim, the whole problem is that this is not a constant; that would be easy. Instead it's a variable that may happen to include the "$" metacharacter (or more than 1).
If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: Pass a parameter that contains a dollar sign

Clay said:
the whole problem is that this is not a constant; that would be easy. Instead it's a variable that may happen to include the "$" metacharacter

Yes, I also thought it was as simple as Tim said.

Here are my two scripts:
$ more dollar_parm
#!/usr/bin/ksh

ABC=$(echo '$def/sam') # generate key
echo $ABC
dollar_parm2 "$ABC" # quotes not needed

$ more dollar_parm2
#!/usr/bin/ksh

echo $1

Both scripts echo: $def/sam

It seems that once you get a $ in a parm, it will stay there. So you should be able to capture the output of makekey and pass that.
Mark Fenton
Esteemed Contributor

Re: Pass a parameter that contains a dollar sign

hmm

I too, think the issue is somewhat easier than Clay avers.

create encrypted password using makekey, assigning same to a variable name. Call subsequent script with this variable as an arguement.

An interactive example:

#!/bin/sh

read password
my_key=`echo ${password}|/usr/lbin/makekey`

;# now call subsequent script with my_key

next_script ${my_key}


next_script then can act on $1 (or whichever arguement was passed)
If you desire to reassign $1 to some other more logically named variable, that is done normally
newpass=$1
when using newpass, just enclose with brackets as was done with my_key in the first script.