Bash shell adding extra single quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash shell adding extra single quotes
# 22  
Old 07-13-2012
Scrutinizer - It does not differ. I have tried exactly that.
Code:
#!/bin/bash -x
#b.sh
echo $1
STMT="cvs commit -m "$1" ./q.sh"
$STMT

Code:
$b.sh "First Second Third"
+ echo First Second Third
First Second Third
+ STMT='cvs commit -m First Second Third ./q.sh'
+ cvs commit -m First Second Third ./q.sh
cvs commit: nothing known about `Second'
cvs commit: nothing known about `Third'
cvs [commit aborted]: correct above errors first!

Quote:
Is there no way to do this without the use of eval?
Moderator's Comments:
Mod Comment Code tags for code, PLEASE!

Last edited by Corona688; 07-13-2012 at 06:06 PM..
# 23  
Old 07-13-2012
Quote:
I do not mean to sound testy or petty, I am just very frustrated with myself right now. Please keep trying for me and my sanity sake. Smilie Thanks
In summary, this is bad:

Code:
STRING="something something \"stuff in quotes\" something else"

$STRING

I suggested this as a alternative:

Code:
STRING="stuff in quotes"

something something "$STRING" something else

...but you went ahead and crammed the whole mess back into STRING as if that could fool it into working somehow.

It doesn't work that way, you can't "trick" or "fool" it. There isn't a "right way". Your entire method, algorithm, line of thought is flawed because shell doesn't work the way you think it ought to.

You have no reason to stuff the entire line into the variable. Stop doing it. There isn't a "right way" to cram the whole thing into a variable. The right way is to not do it at all, because strings do not work that way. Shell won't do that kind of doublethink without eval. You're trying to run a script from a variable and that's wrong.

Do it my way, and your code will work.

Keep doing it your way, and your code will never work.

Until you explain why you think you need to put the entire line into a variable, so we can solve that roadblock forcing you to do so, we're going to keep butting heads on this.

Last edited by Corona688; 07-13-2012 at 06:08 PM..
This User Gave Thanks to Corona688 For This Post:
# 24  
Old 07-13-2012
Quote:
Originally Posted by hpodhrad
Scrutinizer - It does not differ. I have tried exactly that.
[..]
No, actually you haven't. You put the entire command line in a string again. That will not work without eval
This User Gave Thanks to Scrutinizer For This Post:
# 25  
Old 07-16-2012
SWEET!!!!!!!!!!!!

Quote:
You have no reason to stuff the entire line into the variable. Stop doing it.
It took me walking away from this and going camping for a weekend to see things from your point of view Corono688. Once I tried to stop stuffing everything in a variable and let UNIX do it's thing, life was much better. I actually was excited to come to work today to prove to myself your answer was spot on.

Thank you, Thank you, Thank you for not giving up on this hard headed American. Smilie
These 2 Users Gave Thanks to hpodhrad For This Post:
# 26  
Old 07-18-2012
Thanks for all the help on this everyone! Once I got it through that I did not need to "stuff" it all into a variable, life became a whole lot better!!
This User Gave Thanks to hpodhrad For This Post:
# 27  
Old 07-18-2012
Thanks for reporting back and glad that you found a way..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash not recognizing single quotes in Mac?

Hi, I just bought a new mac and have been running a program out of terminal, but even early on I noticed that my single quotes looked a lot different from the ones used in all of the namelists and other files of the program. Specifically, mine are kind of slanted whereas the others are very... (7 Replies)
Discussion started by: jtcastro99
7 Replies

2. 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

3. Shell Programming and Scripting

shell script - to append single quotes and comma

file1 ---- 34556745 32678343 31576776 31455566 21356666 I want to assign the record values to a variable in the below format, so that I can use output in .sql file for querying in database. ('34556745', '32678343', '31576776', '31455566', '21356666') ----------- below is the... (11 Replies)
Discussion started by: rajivrsk
11 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

removing extra double quotes between pipe dilimeter

I have a flat file sample like this - "COURSE"|"ddddd " " dddd"|"sssddd sdsdsdsdx" dddddddd ffffff "aaaaa" dddddddd ffffff sdsdsd"|"xxxxxxx"| "COURSE"|"ffff " " bbbb"|"lllll"| The delimiter is pipe character (|) and the text are enclosed in double quotes... (5 Replies)
Discussion started by: vishalzone
5 Replies

8. Shell Programming and Scripting

Single quotes and double quotes

Hi guys, I have a sed line in double quotes which works fine, but I want it to be in single quotes here is the sed line sed "/abc_def/s/\'.*\'/\'\${abc_def}\'/" can some one give the equivalent to the above script in single quotes Thanks a ton (5 Replies)
Discussion started by: sol_nov
5 Replies

9. Shell Programming and Scripting

How can i use single quotes for SQL command in shell script

Hi. please help me to write the following query in a shell script. the Query is :select no,salary from emp_info where name='$var_name' the following is my code. #! /bin/sh var_name=$1 sqlplus -s user/pwd@DB << EOF select no,salary from emp_info where name="'$var_name'";... (4 Replies)
Discussion started by: little_wonder
4 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