Operating System - HP-UX
1763060 Members
2957 Online
108909 Solutions
New Discussion юеВ

How to pass a character string with parenthesis embedded in ksh shell?

 
SOLVED
Go to solution
Kelvin Yu
Advisor

How to pass a character string with parenthesis embedded in ksh shell?

Hi,

I have some database messages generated with parenthesis and would like to pass into a ksh shell script. Would like to hear suggestion on how to get around this parenthesis problem? Thanks.

Kelvin
10 REPLIES 10
Jeroen Peereboom
Honored Contributor

Re: How to pass a character string with parenthesis embedded in ksh shell?

Kelvin,

what about quotes:
A='(dutch monkey)' (or "(dutch monkey)"
B="$A"

JP.
Jeff_Traigle
Honored Contributor

Re: How to pass a character string with parenthesis embedded in ksh shell?

What problem are you seeing? I just did a quick test of passing parenthesis in a string to a Korn shell script and it worked without issue.

omega# cat > /tmp/test.ksh
#!/usr/bin/ksh

echo "$1"
omega# chmod 750 /tmp/test.ksh
omega# /tmp/test.ksh "(this is a test)"
(this is a test)
omega#
--
Jeff Traigle
Sanjay Kumar Suri
Honored Contributor

Re: How to pass a character string with parenthesis embedded in ksh shell?

Any issue bigger than the following:
xx="(message 1)"
yy="{message 2}"

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Kelvin Yu
Advisor

Re: How to pass a character string with parenthesis embedded in ksh shell?

My sample script looks like the follow:

#test_ksh1 "abc(efg)"

MESSAGE="$*"
remsh HOSTA -n /pagermail.ksh $MESSAGE


The MESSAGE got the string without problem, but when the same message tried to pass to the paging script with parameter $MESSAGE, the parenthesis caused problem.

Hope that this can explain better about my problem. Thanks.

Kelvin
Mark Grant
Honored Contributor

Re: How to pass a character string with parenthesis embedded in ksh shell?

Try this

remsh HOSTA -n /pagermail.ksh "$MESSAGE"
Never preceed any demonstration with anything more predictive than "watch this"
A. Clay Stephenson
Acclaimed Contributor

Re: How to pass a character string with parenthesis embedded in ksh shell?

You need to quote the variable and also it is a good idea to adopt a bit more discipline and enclose EVERY variable in {}'s although it doesn't matter in this case.

remsh HOSTA -n /pagermail.ksh "${MESSAGE}"

If it ain't broke, I can fix that.
Kelvin Yu
Advisor

Re: How to pass a character string with parenthesis embedded in ksh shell?

Hi Clay,

I did that
remsh HOSTA -n /pagermail.ksh "${MESSAGE}"

However, I still failed to pass the string and the error is still on ksh shell i.e.
ksh: syntax error at line 1 : `(' unexpected

If run it locally i.e. without remsh, the script works fine. It looks like remsh complains about the way it calls the script remotely.

Any suggestion what might go wrong in my script. Thanks.

Kelvin

Jeff_Traigle
Honored Contributor
Solution

Re: How to pass a character string with parenthesis embedded in ksh shell?

Fun with quotes. Try:

remsh HOSTA -n "/pagermail.ksh '${MESSAGE}'"
--
Jeff Traigle
Mark Grant
Honored Contributor

Re: How to pass a character string with parenthesis embedded in ksh shell?

Personally, I'd try it this way then

remsh HOSTA -n '/pagermail.ksh \"${MESSAGE}\"'
Never preceed any demonstration with anything more predictive than "watch this"