problem with single quotes in a string and findbug


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with single quotes in a string and findbug
# 1  
Old 01-10-2007
problem with single quotes in a string and findbug in ksh

I'm having trouble manipulating a string that contains single quotes (') in it. I'm writing a ksh script to parse in a few queries from a config file, such as this:

findbug \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class 'isequal' "Development" \)

if i physically call this command it works fine and I get my database results, but I am parsing this string from the config file and storing it in a string variable and then trying to use it and it doesn't work.

For instance I have a variable NewQuery which contains the string.
I do echo $NewQuery and this prints out:
findbug \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class 'isequal' "Development" \)

but if i just do $NewQuery to execute that command it complains:
findbug: Syntax Error: Bad operator 'in'.

Usage: findbug [options] [expr \&\& expr \|\| expr ...]

any idea what i'm doing wrong?

Last edited by bob122480; 01-10-2007 at 03:08 PM..
# 2  
Old 01-10-2007
the shell substitutes the command just one time, $NewQuery substitutes the variable once, an then directly calls the programm findbug with the argument
\(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class 'isequal' "Development" \)
without removing \ and '
# 3  
Old 01-10-2007
yes that is what i'm trying to do, run the program findbug with the argument \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class 'isequal' "Development" \)

but the shell will not execute it when i call $NewQuery. It finds the first single quote 'in' and then complains.

but if i type the whole thing out:
findbug \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class 'isequal' "Development" \)

it executes fine. what is the difference?
# 4  
Old 01-10-2007
Code:
eval findbug "${NewQuery}"

# 5  
Old 01-10-2007
i knew it was gonna be something so easy. thanks so much!
# 6  
Old 01-10-2007
running # $NewQuery generates the command as I wrote above,

running

# findbug \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class 'isequal' "Development" \)

directly in shell, seems to be the same, but real it runs

findbug ((Project in Deployment,HDRCI,LHS,LSS,WUCI && Status in N && New_on lessthan 070107 )) && (Class isequal Development )

not 100%correct, but I hope its clear what I'm trying to say



when you enter a command the shell parses the command for special characters like $ or many others
' \ " prevent the shell from substituting this special characters, but are removed afterwards

type "man ksh" or "man bash" or wait for someone who speaks better english to explain you this Smilie
# 7  
Old 01-11-2007
ok one more question, how do I store the results in a variable?
I am able to pipe it to a file, but I need to store it as well.

I tried this, but no luck:
results= $(eval $NewQuery)
why doesn't this work?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counting number of single quotes in a string

i need to be able to count the number of single quotes ' in the entire string below: "description":"DevOps- Test VM's, System Admins Test VM's ", awk can most likely do this, but here's my attempt using egrep: echo "${STRING}" | egrep -wc '"'"\'"'"' or echo "${STRING}" | egrep -wc... (11 Replies)
Discussion started by: SkySmart
11 Replies

2. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

3. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

4. Shell Programming and Scripting

Having a terrible problem with quotes/single quotes!

Hello. I'm trying to write a bash script that uses GNU screen and have hit a brick wall that has cost me many hours... (I'm sure it has something to do with quoting/globbing, which is why I post it here) I can make a script that does the following just fine: test.sh: #!/bin/bash # make... (2 Replies)
Discussion started by: jondecker76
2 Replies

5. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

6. UNIX for Dummies Questions & Answers

grep single quotes or double quotes

Unix superusers, I am new to unix but would like to learn more about grep. I am very familiar with regular expressions as i have used them for searching text files in windows based text editors. Since I am not very familiar with Unix, I dont understand when one should use GREP with the... (2 Replies)
Discussion started by: george_vandelet
2 Replies

7. Shell Programming and Scripting

problem with echo inserting single quotes

Consider the following script: #!/bin/bash exclude='Archive PST,SystemState' IFS=$"," rsyncExclusions=$(for exclude in ${exclude}; do echo -n -e --exclude=\"${exclude}\"\ ; done) unset IFS echo rsync $rsyncExclusions test rsync -avh --delete --delete-excluded "$rsyncExclusions"... (7 Replies)
Discussion started by: jelloir
7 Replies

8. Shell Programming and Scripting

Problem renaming a file with single quotes

Hi, I am trying to create a script which validates the incoming source files. The script has File name Pattern as Argument. The First part of the script validates if there are any files available if then echo "\n Files are available to process \n" else echo "\n File does not... (9 Replies)
Discussion started by: dsshishya
9 Replies

9. UNIX for Dummies Questions & Answers

Add single quotes in string

Hi All, I love this site, it helps newbie people like me and I appreciate everyone's help! Here is my questions. I am trying to concatenate a single quote into a character/string from a text file for each line (lets say ABC should look like 'ABC'). I tried to use awk print command to do... (1 Reply)
Discussion started by: mrjunsy
1 Replies

10. Shell Programming and Scripting

Double quotes or single quotes when using ssh?

I'm not very familiar with the ssh command. When I tried to set a variable and then echo its value on a remote machine via ssh, I found a problem. For example, $ ITSME=itsme $ ssh xxx.xxxx.xxx.xxx "ITSME=itsyou; echo $ITSME" itsme $ ssh xxx.xxxx.xxx.xxx 'ITSME=itsyou; echo $ITSME' itsyou $... (3 Replies)
Discussion started by: password636
3 Replies
Login or Register to Ask a Question