LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-16-2008, 09:45 PM   #1
qipman
LQ Newbie
 
Registered: Jul 2006
Posts: 14

Rep: Reputation: 0
echo and carrots in a script


Hello.
I have been trying to find a way to pipe the following to a file within a script that does this for each entry in an input file. However, obviously the carrots do not work with echo:

<echo 'img src="$i.jpg" caption="$i" link="http://kozybabies.com/shopping.htm" />' >> test.xml

This command work in the script, and I am adding the carrots using an external file (kind of barbaric):

echo 'img src="'$i.jpg'" caption="'$i'" link="http://test.zone/test.htm"' >> test.xml

Does anyone know a way to pipe the original command out keeping the carrots in place..?

Thanks,
Lou
 
Old 05-16-2008, 11:28 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Maybe I need to eat more carrots because I don't see any carets (^) in your message.
 
Old 05-16-2008, 11:55 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I really don't know which character you are referring to. Enter "help echo" or "man echo" for options such as -e which would allow you to use certain escape sequences which can include a character of the form \0nnn. Also look at escaping the character you don't want the shell to handle. A variable, like $i needs to be in double quotes if you need to expand it.

Your second line looks OK except for missing the beginning and closing tags.

Also look at using a here document to construct a html page.

You could construct the top of the page in a here document, iterate through the arguments in a loop, and then finish the documents with another here document.

The info bash manual has information about HERE documents.

Another option is to use the "printf" command instead of echo.

Last edited by jschiwal; 05-17-2008 at 12:43 AM.
 
Old 05-17-2008, 11:38 AM   #4
qipman
LQ Newbie
 
Registered: Jul 2006
Posts: 14

Original Poster
Rep: Reputation: 0
Sorry for the confusion, I was working off very little sleep when I wrote out the original post.

What I needed to do is pipe this line from my script into an output file. The problem is that echo removes the quotes in the process.

However, the printf command worked perfectly, thanks much for the info.

printf '<img src="'$i.jpg'" caption="'$i'" link="'http://zome.com/shopping.htm'" />\n' >>out /r >> $WHOME/images.xml

Regards,
Lou
 
Old 05-18-2008, 07:45 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
perhaps this should also work:
Code:
echo "<img src=\"${i}.jpg\" caption=\"${i}\" link=\"http://zome.com/shopping.htm\" />" >> $WHOME/images.xml
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
echo ascii art script doesn't display correctly? Romanus81 Slackware 5 03-07-2008 11:01 AM
Disable Echo Mode in Expect Script gjagadish Programming 2 04-25-2007 03:28 PM
howto write a script to echo files with spaces in the name dsids Linux - Newbie 1 11-28-2006 07:18 AM
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 12:08 AM
crontabbed shell script, trying to echo/cat something zaubara Programming 2 06-13-2004 07:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration