Sponsored Content
Full Discussion: trouble with: read -d '\r'
Top Forums Shell Programming and Scripting trouble with: read -d '\r' Post 302359982 by HowardL on Thursday 8th of October 2009 01:29:04 AM
Old 10-08-2009
trouble with: read -d '\r'

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:
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 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.
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

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:
Code:
~>  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!


Last edited by HowardL; 10-08-2009 at 02:34 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

The trouble about SU ...

Hi all, having read lots of posts about SU I don't quiet understand this : I'm doing regular backups of my database (u betta do) and therefore use su - username -c "sqlscript special data_base" in a unixscript which is even using cron. (yep!) Now I need some other script, still with this... (4 Replies)
Discussion started by: nulnul7
4 Replies

2. Solaris

Trouble with tr

I'm not sure where to post this but it's happening on a SunOS 5.8 server so I'll try here. I've discovered some unexpected behavior when using tr. For example: echo a | tr Z echo b | tr a echo a | tr B echo a | tr B echo a | tr A (8 Replies)
Discussion started by: Mike@Work
8 Replies

3. UNIX for Dummies Questions & Answers

X trouble

Hi there, I'm new to unix-environments. I'm richard, and i'm mostly a web-developer, under php. I've done work in unix env before, but never had my own. Today, I've got debian 3.1 r4 from the official site, and i've attempted to install it twice. I installed it initially as "Desktop... (0 Replies)
Discussion started by: izua
0 Replies

4. UNIX for Dummies Questions & Answers

trouble using read to store values in variables from command output

I know there are caveats about using read in pipelines because read is treated by a subshell. I know this but I can't think of any way to accomplish this regardless, I'm still a rookie. I hope somebody will be able to interpret what it is that I'm trying to accomplish and correct me. ... (2 Replies)
Discussion started by: ProGrammar
2 Replies

5. Programming

Cannot read a file with read(fd, buffer, buffersize) function

# include <stdio.h> # include <fcntl.h> # include <stdlib.h> # include <sys/stat.h> int main(int argc, char *argv) { int fRead, fPadded, padVal; int btRead; int BUFFSIZE = 512; char buff; if (argc != 4) { printf ("Please provide all of the... (3 Replies)
Discussion started by: naranja18she
3 Replies

6. UNIX for Advanced & Expert Users

read() wont allow me to read files larger than 2 gig (on a 64bit)

Hi the following c-code utilizing the 'read()' man 2 read method cant read in files larger that 2gig. Hi I've found a strange problem on ubuntu64bit, that limits the data you are allowed to allocate on a 64bit platform using the c function 'read()' The following program wont allow to allocate... (14 Replies)
Discussion started by: monkeyking
14 Replies

7. Shell Programming and Scripting

Read Embedded Newline characters with read (builtin) in KSH93

Hi Guys, Happy New Year to you all! I have a requirement to read an embedded new-line using KSH's read builtin. Here is what I am trying to do: run_sql "select guestid, address, email from guest" | while read id addr email do ## Biz logic goes here done I can take care of any... (6 Replies)
Discussion started by: a_programmer
6 Replies

8. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

9. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

10. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 12:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy