Hello,
I am writing a script to talk to my pop server.
All the lines returned from the server end with \r\n (0x0d 0x0a)
The read command trims the 0x0a and the line is left with 0x0d ending.
I see how I can use the tr utility do delete it:
~> 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 nice , but it would be more efficient to just stop reading when \r is encountered.
So I have been trying to figure out how to get read to see the \r.
~> 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
How can this be done?
---------- Post updated 10-08-09 at 01:29 AM ---------- Previous update was 10-07-09 at 11:32 PM ----------
I'll be dog , I think I found an answer in ABS:
~> volume="hi"$'\x0d'" there"; echo -n $volume > xfile; hexdump -C xfile;
00000000 68 69 0d 20 74 68 65 72 65 |hi. there|
00000009
~> read -d '\r' < xfile; echo "$REPLY"
there
~> read -d $'\x0d' < xfile; echo "$REPLY"
hi
# dude!