LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-06-2008, 03:48 PM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 51
bash: How to echo plenty of ' and " chars ?


Hello,

Sorry for the ultra n00b question, even if already programing.
I would like just to have a script that put that content into .festivalrc:
Code:
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)

Hence, the script would be :

myscript.sh
Code:
#!/bin/sh
echo "(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")" > ~/.festivalrc
echo "(Parameter.set 'Audio_Method 'Audio_Command)" >> ~/.festivalrc
but this code of course do not work
thank you
(and sorry for the n00b question again)
 
Old 05-06-2008, 03:52 PM   #2
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 476
Blog Entries: 111

Rep: Reputation: 74
Escape the quotes. For instance:

echo "This is a \"test\" using different 'kinds' of \"quotes\""

will output:

This is a "test" using different 'kinds' of "quotes"

So you'd need this:

#!/bin/sh
echo "(Parameter.set 'Audio_Command \"aplay -q -c 1 -t raw -f s16 -r $SR $FILE\")" > ~/.festivalrc
echo "(Parameter.set 'Audio_Method 'Audio_Command)" >> ~/.festivalrc

Last edited by rocket357; 05-06-2008 at 03:57 PM.
 
Old 05-06-2008, 03:56 PM   #3
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by rocket357 View Post
Escape the quotes. For instance:

echo "This is a \"test\" using different 'kinds' of \"quotes\""

will output:

This is a "test" using different 'kinds' of "quotes"
Ahh and can you do this \' \' ?
since you can do :
echo '" this is a text "'
...
 
Old 05-06-2008, 04:00 PM   #4
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 476
Blog Entries: 111

Rep: Reputation: 74
Umm, yeah, but you wouldn't require \' since you're main quote is using double quotes.

You could look at it like this:

echo 'This is a \'single\' quoted line. I shouldn\'t have to escape "double quotes" '

echo "This is a \"double\" quoted line. I shouldn't have to escape 'single quotes' "

Last edited by rocket357; 05-06-2008 at 04:02 PM.
 
Old 05-06-2008, 05:07 PM   #5
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 35
Code:
cat <<! >~/.festivalrc
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
!
or (if you don't want to expand SR and FILE):

Code:
cat <<\! >~/.festivalrc
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
!

Last edited by radoulov; 05-06-2008 at 05:09 PM.
 
Old 12-28-2008, 12:47 PM   #6
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by radoulov View Post
Code:
cat <<! >~/.festivalrc
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
!
or (if you don't want to expand SR and FILE):

Code:
cat <<\! >~/.festivalrc
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
!

I put that in a script and it says taht " is somehow missing or end of file

nota: \ added to preserve "$"

Code:
 	cat <<! >~/.festivalrc
	(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r \$SR \$FILE")
	(Parameter.set 'Audio_Method 'Audio_Command)
	!
 
Old 12-28-2008, 02:33 PM   #7
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 35
What is the exact command you're running?
Here I'm using bash:

Code:
$ cat <<\! >~/.festivalrc
> (Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
> (Parameter.set 'Audio_Method 'Audio_Command)
> !
$ cat .festivalrc 
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
Notice that some shells will require double \\ to quote the heredoc if you use ! as a delimiting identifier.
 
Old 12-29-2008, 02:40 AM   #8
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by radoulov View Post
What is the exact command you're running?
Here I'm using bash:

Code:
$ cat <<\! >~/.festivalrc
> (Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
> (Parameter.set 'Audio_Method 'Audio_Command)
> !
$ cat .festivalrc 
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
Notice that some shells will require double \\ to quote the heredoc if you use ! as a delimiting identifier.
Actually I have to put the commands in a bash script, that willl be run afterwards with ./script or sh script, and will generate that .festivalrc file.
 
Old 12-29-2008, 02:50 AM   #9
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 35
Quote:
Originally Posted by frenchn00b View Post
Actually I have to put the commands in a bash script, that willl be run afterwards with ./script or sh script, and will generate that .festivalrc file.
This is how I'm running it from a script:

Code:
$ ./s
generating /home/sysadmin/.festivalrc ... done
displaying the content of /home/sysadmin/.festivalrc

(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
And this is the script:
Code:
#! /bin/bash

rcfile="$HOME/.festivalrc"

printf 'generating %s ... ' "$rcfile"

cat <<\! >"$rcfile"
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
!

printf 'done\n'

printf 'displaying the content of %s\n\n' "$rcfile"

cat "$rcfile"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: how to replace strings of a file with some " chars ? frenchn00b Linux - General 1 03-01-2008 09:10 AM
bash, filenames, special chars zomane Programming 3 06-15-2007 04:55 AM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 02:14 PM
(bash) echo "#!/bin/bash" event not found - trying to generate profiles automatically jimieee Programming 9 05-03-2006 10:24 AM
"admission denied" even though i am root and there's plenty of space ungua Suse/Novell 5 02-12-2005 07:45 AM


All times are GMT -5. The time now is 05:04 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration