GIDForums  

Go Back   GIDForums > Computer Forums > Computer Software Forum - Linux
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Oct-2009, 09:14
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

bash: How to: read -d '\r' . . (delimit on a meta character)


Hi again , How about this one:
I am writing a script to talk to my pop server.
All the lines returned from the server are crlf (0x0d 0x0a)
The read command trims the 0x0a and the line is left with 0x0d ending.
I figured out how to use the tr utility do delete it:
Code:
~> s=abcdex; s=$(echo $s | tr x '\r'); echo -n $s > xf1; hexdump -C xf1; 00000000 61 62 63 64 65 0d |abcde.| 00000006 ~> s=$(echo $s | tr -d '\r'); echo -n $s > xf1; hexdump -C xf1; 00000000 61 62 63 64 65 |abcde| 00000005
Which is cool , but it be even better to just stop reading there.
So I have not been able to figure out how to get read to see the \r.
examples:

Code:
~> s=abcdexyz; s=$(echo $s | tr x '\r'); echo -n $s > xf1; hexdump -C xf1; 00000000 61 62 63 64 65 0d 79 7a |abcde.yz| 00000008 # So there is an 0x0d , Now use read -d on a regular character: ~> read -d e < "xf1"; echo "$REPLY" abcd # But I can't seem to figure out how to get read to id the 0x0d: ~> read -d \r < "xf1"; echo "$REPLY" yzcde ~> read -d '\r' < "xf1"; echo "$REPLY" yzcde ~> read -d '\\r' < "xf1"; echo "$REPLY" yzcde ~> read -d \\r < "xf1"; echo "$REPLY" yzcde ~> read -d 0x0d < "xf1"; echo "$REPLY" yzcde
Why is tr able to id the '\r' and bash read not? (because it was designed to?)
Is this where I need to learn to use RE in bash?
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash test for a dot terminatior in pop3 server LIST output Howard_L Computer Software Forum - Linux 3 29-Sep-2009 10:40
Search and replace char in same text file lanz C Programming Language 6 17-May-2009 13:21
Re: Things to Avoid in C/C++ -- gets() , Part 1 WaltP C Programming Language 5 21-Jun-2007 13:13
read Function [C++] FFCD C++ Forum 2 28-Nov-2006 17:53
Menu of character strings aijazbaig1 C Programming Language 21 27-Jul-2006 04:07

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.