Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 1st November 2005, 07:51 PM
essdeeay's Avatar
essdeeay Offline
Registered User
 
Join Date: Oct 2004
Posts: 30
Question How do I prevent echo eating spaces?

Hello

I'm writing a script in which I need to insert date/time stamps in exactly the same format as syslog (ie. %b %e %T). However, echo is eating the blank padded space for (%e).

I will insert the date/time stamp like this:
Code:
echo $DATE This is a date time stamp
and so have defined the DATE variable like this:
Code:
DATE=`date '+%b %e %T'`
This is where echo eats up the blank padded space.

If I were to insert the date/time stamp using "$DATE" instead of just $DATE, echo does not eat the spaces, but I don't want to do that and can't figure out how to include this in the actual DATE variable.

If I use sed (it's getting dirty and cumbersome now), I can do this (using echo -E $DATE):
Code:
DATE=`date '+%b %e %T' | sed 's/ /*/g'`
Nov**1*19:21:27
Which works as expected, but when I try and use an escaped space instead of an asterisk in the replacement text, it just won't work. Below, what I think should be being fed back to the echo command is:
Code:
Nov\ \ 1\ 19:21:27
but this is what I get instead:
Code:
DATE=`date '+%b %e %T' | sed 's/ /\\ /g'`
Nov 1 19:21:27
Any help would be appreciated.

Many thanks,
Steve
Reply With Quote
  #2  
Old 1st November 2005, 08:10 PM
Firewing1's Avatar
Firewing1 Offline
Administrator
 
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224
You have to use quotes:
...
echo "$DATE This is a date time stamp"
Firewing1
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
  #3  
Old 1st November 2005, 08:52 PM
essdeeay's Avatar
essdeeay Offline
Registered User
 
Join Date: Oct 2004
Posts: 30
Thanks for your reply Firewing1

I was hoping to not have to use the " " to preserve the variable, because AFAIK you normally don't have to. However, it seems " " is the answer so that's the way I shall go.

Again, many thanks!
Steve
Reply With Quote
  #4  
Old 1st November 2005, 09:49 PM
Firewing1's Avatar
Firewing1 Offline
Administrator
 
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224
Yeah... BASH I found isn't the best language for programming. Stuff like this makes it annoying. I much rather PHP.
Firewing1
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
Reply

Tags
eating, echo, prevent, spaces

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
md0_resync eating up CPU stocks29 Using Fedora 2 31st March 2007 09:49 PM
Eggcups eating CPU? sid1950 Using Fedora 2 10th February 2007 10:59 AM
VNC eating up CPU? asun Using Fedora 5 5th July 2006 05:37 PM
FC1 are eating up my HD... TopDog EOL (End Of Life) Versions 7 15th July 2004 02:43 PM


Current GMT-time: 03:58 (Thursday, 20-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat