Eval command with space, quote and bracket characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Eval command with space, quote and bracket characters
# 1  
Old 07-10-2015
Data Eval command with space, quote and bracket characters

Hi,
I am Pradnya Gandhe trying to use in shell script.
I want to use a bit complicated command using eval command in a shell script.
Code:
<path to>\wsadmin.sh -lang jython -conntype NONE -c "AdminApp.install('war file path', '[ -appname IDSWebApp -contextroot /IDSWebApp -MapModulesToServers [[ \"string" IDSWebApp.war,WEB-INF/web.xml WebSphere:server=server1 ]] -MapWebModToVH [[ \"string\" IDSWebApp.war,WEB-INF/web.xml default_host ]] -MapRolesToUsers [[ allusers AppDeploymentOption.No AppDeploymentOption.Yes \"\" \"\" AppDeploymentOption.No \"\" \"\" ]] ]')"

Works correctly as expected on shell prompt
Code:
<path to>\wsadmin.sh -lang jython -conntype NONE
wsadmin>above command

works correctly

I want to use this command in shell script, so I used eval command
eval "command" like following
Code:
eval <path to>\wsadmin.sh -lang jython -conntype NONE -c "AdminApp.install('war file path', '[ -appname IDSWebApp -contextroot /IDSWebApp -MapModulesToServers [[ \"string" IDSWebApp.war,WEB-INF/web.xml WebSphere:server=server1 ]] -MapWebModToVH [[ \"string\" IDSWebApp.war,WEB-INF/web.xml default_host ]] -MapRolesToUsers [[ allusers AppDeploymentOption.No AppDeploymentOption.Yes \"\" \"\" AppDeploymentOption.No \"\" \"\" ]] ]')"

It gives following error->
Code:
pg.sh: command substitution: line 10: syntax error near unexpected token `('
pg.sh: command substitution: line 10: `<path to>\wsadmin.sh -lang jython -conntype NONE -c '"'AdminApp.install('war file path', '[ -appname IDSWebApp -contextroot /IDSWebApp -MapModulesToServers [[ "string" IDSWebApp.war,WEB-INF/web.xml WebSphere:server=server1 ]] -MapWebModToVH [[ "string" IDSWebApp.war,WEB-INF/web.xml default_host ]] -MapRolesToUsers [[ allusers AppDeploymentOption.No AppDeploymentOption.Yes "" "" AppDeploymentOption.No "" "" ]] ]')'"''

I want to know rules to used in eval if command within it contains characters like brackets, quotes, space, etc.

This is all issue of characters which when passed over eval generates error.

Pls guide me.

Thanks and regards,
Pradnya Gandhe

Last edited by Don Cragun; 07-10-2015 at 03:06 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 07-10-2015
I am lost on several counts here.

If I have a command (for example date) that works at a shell prompt outside of a script, I can run that same command inside a shell script without preceding it by eval. Why do you think you need eval here?

The command that you say works has mismatched double quotes. I can't believe that it is working for you at a shell prompt outside of a shell script for you. And that is assuming that <path to>\wsadmin.sh is not trying to run the to command with input redirected from the file named path and output redirected to the file wsadmin.sh???

Why are you getting diagnostics reporting a problem on line 10 of your script when the script you have shown us only contains one line?

I don't see any command substitution in the command you say is working nor in the shell script you have shown us. Why is the shell you're using complaining about command substitution? Is there a command substitution started on a line in your script before the line you have shown us?

What operating system and shell are you using?
# 3  
Old 07-10-2015
Hi Don,
Yes, you are right.
I dont need to use eval if I have a command that runs successfully out of the shell script.
Now I am calling same command within shell script.
I was UN-necessarily wasting my time to make it work with eval. Somehow it got sleep from my mind that we can use the commands withing shell script.

Thanks for point this out. It saved my day.

Thanks and regards,
Pradnya Gandhe
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

2. Shell Programming and Scripting

Replacing trailing space with single quote

Platform : RHEL 5.8 I want to end each line of this file with a single quote. $ cat hello.txt blueskies minnie mickey gravity snoopyAt VI editor's command mode, I have used the following command to replace the last character with a single quote. ~ ~ ~ :%s/$/'/gNow, the lines in the... (10 Replies)
Discussion started by: John K
10 Replies

3. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies

4. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

ksh, difference between double bracket and single bracket

Can somebody tell me the difference between double brackets and single brackets, when doing a test. I have always been acustomed to using single brackets and have not encountered any issues to date. Why would somebody use double brackets. Ie if ] vs if Thanks to... (2 Replies)
Discussion started by: BeefStu
2 Replies

6. Shell Programming and Scripting

Strange result of eval, how does eval really work with ssh?

Hi all, some small script with eval turned me to crazy. my OS is linux Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux below script works well #!/bin/bash eval ssh remotehost date eval ssh remotehost ls below... (1 Reply)
Discussion started by: summer_cherry
1 Replies

7. Shell Programming and Scripting

Eval command help

I have file called myfile which has the text "myserver" in it. I need to have a command to ping "myserver". How would I do that? I tried when I type at the terminal I get the output as . How do I do something like a ? thanks, Nick (5 Replies)
Discussion started by: nikhilfake
5 Replies

8. Shell Programming and Scripting

Processing data that contains space and quote delimiters

I need to write a Bash script to process a data file that is in this format: 1 A B C D E 2 F G "H H" I J As you can see, the data is delimited by a space, but there are also some fields that contain spaces and are surrounded by double-quotes. An example of that is "H H". I wrote... (7 Replies)
Discussion started by: RickS
7 Replies

9. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

10. Shell Programming and Scripting

Multiple characters including single quote in delimiter

Hello, I need to replace the comma to something else between the single quote: 1aaa,bbb,'cc,cc','ddd',1 2aaa,bbb,'ccc','d,d',0 to 1aaa,bbb,'cc<comma>cc','ddd',1 2aaa,bbb,'ccc','d<comma>d',0 Can someone help? Thanks. (2 Replies)
Discussion started by: bgirl
2 Replies
Login or Register to Ask a Question