The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple Question aforball UNIX for Dummies Questions & Answers 3 03-04-2008 01:26 PM
sed - simple question scotty_123 Shell Programming and Scripting 13 03-28-2007 11:23 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 11:29 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 10:03 AM
Simple ksh question frustrated1 Shell Programming and Scripting 1 11-05-2003 09:41 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-25-2002
Registered User
 

Join Date: Jan 2002
Posts: 13
Simple Question

Friends,

I did following exercise

$ echo '' > test
$ od -b test

$ echo "">test
$ od -b test

$echo > test
$od -b test

Every time I got the following output
0000000 012
0000001

But 012 is octal value for new line character .
Even though there is no apperent new line character in test file
the output of command showed 012.
Will anybody please explain the reason for the output ?
Forum Sponsor
  #2  
Old 01-25-2002
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
What is the purpose of your input?

Also, what flavor of UNIX is this on?

I believe that a file begins with a newline char or some other unseen chars.

I had trouble in a script one time trying to test for 0 bytes because of bogus chars in the file even though it shows 0 bytes from an "ls filename" output.

Weird...
__________________
My brain is your brain
  #3  
Old 01-25-2002
Registered User
 

Join Date: Jan 2002
Posts: 5
j1yant,

From the man page for echo, I found the following...

DESCRIPTION
The echo utility writes its arguments, separated by BLANKs
and terminated by a NEWLINE, to the standard output. If
there are no arguments, only the NEWLINE character will be
written.

So this explains why you always get a newline.

Also, in that man page, you'll see that some echos ( shell dependant ) allow for a flag to be passed to eliminate the adding of a NEWLINE to the end of the character.

Hope this helps...
T
  #4  
Old 01-25-2002
Registered User
 

Join Date: Jan 2002
Posts: 5
Kelam...

Are you sure it's a NEWLINE character at the start of every file?
  #5  
Old 01-25-2002
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
If you think about it a file with nothing in it only has a newline in it...


Because the file as "spaces followed by a newline". So your answer is yes. But the file has to be empty for this to be the case.

That is probably why my 0 byte test failed.

here is my output using your test criteria.

-root:/tmp> echo "" > test # no blank in between
-root:/tmp> od -b test
0000000 012
0000001

-root:/tmp> echo > test #echo nothing
-root:/tmp> od -b test
0000000 012
0000001

-root:/tmp> echo " " > test # echo one blank character
-root:/tmp> od -b test
0000000 040 012
0000002
__________________
My brain is your brain
  #6  
Old 01-26-2002
Registered User
 

Join Date: Jan 2002
Posts: 13
Troccola,

Yes ,in the man page explantion is given as to why new line character appears.

I want to know which flag you passed to eliminate new line character. Will you please demonstrate it?

J1yant
  #7  
Old 01-29-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
With echo, you would want to do something like this:

echo "\c" > file

If that doesn't work, you might need to do this:

echo -e "\c" > file

But that best way to do it is:

>file
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0