- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Inserting \ character in a string passed to anothe...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 09:24 PM
10-09-2003 09:24 PM
I have a shell script that receives a command line and executes a remote shell and passes the command string as argument.
Content of shell script:
cmd=$1
remsh host1 -l user1 -n "export DISPLAY=$DISPLAY;/opt/app/xpto.sh $cmd
This executes:
remsh host1 -l user1 -n "export DISPLAY=$DISPLAY;/opt/app/xpto.sh xpto (12)
When executing, I get the error:
I get the error
sh: Syntax error at line 1 : `(' is not expected.
I am trying to insert some \ character before the ( character but without success:
parsed_cmd=`echo $cmd | sed "s/(/\\0050/g" | sed "s/(/\(/g"`
Any help/suggestion is highly appreciated.
TIA.
Kind Regards,
Rui.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 10:15 PM
10-09-2003 10:15 PM
Re: Inserting \ character in a string passed to another command
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 10:35 PM
10-09-2003 10:35 PM
Re: Inserting \ character in a string passed to another command
Thanks for your suggestion.
The problem is if you have this within a script it will fail:
In script:
remsh host1 -l user1 -n "export DISPLAY=$DISPLAY;echo $parsed_cmd"
It returns:
ksh: syntax error at line 1 : `(' unexpected
TIA,
Rui.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 10:49 PM
10-09-2003 10:49 PM
Re: Inserting \ character in a string passed to another command
If I understand you correctly I would have though enclosing $cmd in " marks might help. You might need to enclose it with \" if being part of the remsh though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 11:05 PM
10-09-2003 11:05 PM
Re: Inserting \ character in a string passed to another command
--
#PS1="# "
# cmd="xpto (12)"
# parsed_cmd=$(echo $cmd|sed -e "s/(/\\\\(/" -e "s/)/\\\\)/")
# echo $parsed_cmd
xpto \(12\)
# remsh crimple "echo $parsed_cmd"
xpto (12)
#
--
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 11:05 PM
10-09-2003 11:05 PM
Re: Inserting \ character in a string passed to another command
You are right I was not clear enough...
This is my script:
cat cmd.sh
#! /usr/bin/ksh
cmd="COMMAND (12)"
parsed_cmd=`echo $cmd|sed -e "s/(/\\\\(/" -e "s/)/\\\\)/"`
remsh host1 -l user1 -n "export DISPLAY=$DISPLAY;echo $parsed_cmd"
... and it returns:
ksh: syntax error at line 1 : `(' unexpected
TIA,
Rui.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 11:14 PM
10-09-2003 11:14 PM
SolutionIt's the backticks.
Change
--
parsed_cmd=`echo $cmd|sed -e "s/(/\\\\(/" -e "s/)/\\\\)/"`
-- to --
parsed_cmd=$(echo $cmd|sed -e "s/(/\\\\(/" -e "s/)/\\\\)/")
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 11:25 PM
10-09-2003 11:25 PM
Re: Inserting \ character in a string passed to another command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2003 12:08 AM
10-10-2003 12:08 AM
Re: Inserting \ character in a string passed to another command
...and I think that the error resembles what you get when doing this:
$ cmd=COMMAND (12)
ksh: syntax error: `(' unexpected
In your first posting you say that the content of the shell script is:
cmd=$1
If this is in fact the case, try changing it to:
cmd="$"
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2003 12:43 AM
10-11-2003 12:43 AM
Re: Inserting \ character in a string passed to another command
Many thanks to Graham Cameron.
Cheers,
Rui