Bash shell adding extra single quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash shell adding extra single quotes
# 15  
Old 07-13-2012
Or if you want the message to be optional:

Code:
read MESSAGE
[ -z "$MESSAGE" ] && cvs commit ./q.s
[ -z "$MESSAGE" ] || cvs commit -m "${MESSAGE}" ./q.s

# 16  
Old 07-13-2012
I have tried to get this to the bare essentials. What I want to do is pass a string from a.sh to b.sh and echo that to the screen.

Code:
#!/bin/bash -x
#a.sh
echo $1
./b.sh $1

#!/bin/bash -x
#b.sh
echo $1

$a.sh "test multi"
+ echo test multi
test multi
+ ./b.sh test multi
+ echo test
test

Why can't I get this to work???????? I have gone back through this thread and the only one I can get to work is the "eval" which is too susceptible to attack. Sorry, but I am just getting frustrated with myself.
Moderator's Comments:
Mod Comment code tags for code.

Last edited by Corona688; 07-13-2012 at 01:55 PM..
# 17  
Old 07-13-2012
If you don't put strings in quotes, the shell splits on them on spaces. The quotes are not considered part of the string -- they define whether splitting happens or not inside it.

Substitution happens inside double quotes, but not single ones. So use double quotes here.

"$1"

Note that -x might not show the quotes anyway... This is because -- I repeat -- the quotes are not part of the string. They're delimiters. They define where one string stops and ends, but aren't included in the data itself.

I also note that if you'd used my code as given, it would have worked; it included quotes where necessary...
# 18  
Old 07-13-2012
I removed the -x

Code:
#!/bin/bash
#a.sh
echo $1
./b.sh "$1"

Code:
#!/bin/bash
#b.sh
echo $1
STMT="cvs commit -m "$1" ./q.sh"
$STMT

How does that differ from your code as given?

This is my output trying to run either script.

Code:
$a.sh "This is"
This is
This is
cvs commit: nothing known about `is'
cvs [commit aborted]: correct above errors first!

Code:
$b.sh "This is"
This is
cvs commit: nothing known about `is'
cvs [commit aborted]: correct above errors first!
$


When I use this code:
Code:
#!/bin/bash
#b.sh
echo $1
STMT="cvs commit -m "$1" ./q.sh"
echo $STMT

the output is
Code:
cvs commit -m This is ./q.sh

That statement will not execute. This will
Code:
cvs commit -m "This is" ./q.sh

This is the cvs syntax
Code:
cvs [cvs-options] commit [command-options] [filename]

so if I don't have the double quotes this command
Code:
cvs commit -m This is ./q.s

h
will attempt to commit filename "is" with message "This". So I do need the double quotes, right? They ARE part of the string I am passing to the cvs statement.

---------- Post updated at 03:27 PM ---------- Previous update was at 03:25 PM ----------

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

Last edited by Scrutinizer; 07-13-2012 at 05:29 PM.. Reason: code tags
# 19  
Old 07-13-2012
Try this (using Corona688's suggestion in #14):
Code:
#!/bin/bash -x
echo "$1"
cvs commit -m "$1" ./q.s

Code:
./test.sh "This is"

# 20  
Old 07-13-2012
Tried something new
Code:
#!/bin/bash -x
#b.sh
echo $1
STMT="cvs commit -m "\"$1\"" ./q.sh"
echo $STMT
STMT2="cvs commit -m "$1" ./q.sh"
echo $STMT2
STMT3="cvs commit -m \"$1\" ./q.sh"
echo $STMT3
STMT4="cvs commit -m \""$1"\" ./q.sh"
echo $STMT4

L$b.sh "First Second Third"
+ echo First Second Third
First Second Third
+ STMT='cvs commit -m "First Second Third" ./q.sh'
+ echo cvs commit -m '"First' Second 'Third"' ./q.sh
cvs commit -m "First Second Third" ./q.sh
+ STMT2='cvs commit -m First Second Third ./q.sh'
+ echo cvs commit -m First Second Third ./q.sh
cvs commit -m First Second Third ./q.sh
+ STMT3='cvs commit -m "First Second Third" ./q.sh'
+ echo cvs commit -m '"First' Second 'Third"' ./q.sh
cvs commit -m "First Second Third" ./q.sh
+ STMT4='cvs commit -m "First Second Third" ./q.sh'
+ echo cvs commit -m '"First' Second 'Third"' ./q.sh
cvs commit -m "First Second Third" ./q.sh

Still not right......

Last edited by Scott; 07-13-2012 at 06:27 PM.. Reason: Code tags
# 21  
Old 07-13-2012
Quote:
Originally Posted by hpodhrad
[..]
Code:
#!/bin/bash
#b.sh
echo $1
STMT="cvs commit -m "$1" ./q.sh"
$STMT

How does that differ from your code as given?

[..]
You are still using the indirect message of executing a string and for that you need eval, so this will not work...

If you want to "hide" the cvs command you could use a function as I suggested earlier. I'll give you an example:

Code:
#!/bin/bash -x

commit(){
  cvs commit -m "$1" ./q.s
}

echo "$1"
commit "$1"


Last edited by Scrutinizer; 07-13-2012 at 05:50 PM..
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