Read command in ksh

Read command in ksh

Post by Kevin Kalste » Fri, 11 Apr 1997 04:00:00



Ive got a script with the following line:

read GREP_DATA
echo GREP_DATA is $GREP_DATA

unfortunately though if i enter ...
NC    100

the script displays ...
GREP_DATA is NC 100

The problem is that it is not including the extra spaces between the NC
and the 100.   How does one do this?  please answer me in email as i dont
read newsgroups much.  thanks,

Kevin

 
 
 

Read command in ksh

Post by Bill Marc » Sat, 12 Apr 1997 04:00:00



> Ive got a script with the following line:

> read GREP_DATA
> echo GREP_DATA is $GREP_DATA

> unfortunately though if i enter ...
> NC    100

> the script displays ...
> GREP_DATA is NC 100

> The problem is that it is not including the extra spaces between the NC
> and the 100.   How does one do this?  please answer me in email as i dont
> read newsgroups much.  thanks,

echo GREP_DATA is "$GREP_DATA"
--
Bill Marcum    bmarcum at iglou dot com
"...and eleven long haired friends of Jesus in a chartreuse microbus..."

 
 
 

Read command in ksh

Post by Icarus Spar » Sat, 12 Apr 1997 04:00:00




>Ive got a script with the following line:

>read GREP_DATA
>echo GREP_DATA is $GREP_DATA

>unfortunately though if i enter ...
>NC    100

>the script displays ...
>GREP_DATA is NC 100

>The problem is that it is not including the extra spaces between the NC
>and the 100.   How does one do this?

I am afraid that you show a misunderstanding of how two things work. Consider
first what output you would expect from
echo NC    100
As the shell uses whitespace to delimit arguements, but does not care if there
is more than one space, you would get
NC 100
So if you wish to preserve the whitespace, you need to put the variable inside
double quotes, i.e.  echo "$GREP_DATA"  or echo "NC    100".
The other, more subtle point, refers to the way that read works. It will
normally strip any initial characters specified in $IFS, so the correct
script would be (assuming that you don't have a modern shell with 'read -r')
IFS='' read GREP_DATA
echo "GREP_DATA is $ $GREP_DATA"

Of course ksh is a modern shell, so you should modify the command.

Quote:>please answer me in email as i dont read newsgroups much. thanks,

Don't you feel it is a little rude to ask questions but not wait around for
the answers?
 
 
 

1. using the command history with read in ksh

Hi,

Can I use a command history with the read function in ksh (Standard ksh
from Solaris 8 and 9)?
Or is there any other method to have a command history for read ?

Example code:

#!/usr/bin/ksh

sub1() {
   echo "Enter command: "

### here I want to have a command history
   read USERINPUT

   echo "Your input is \"$USERINPUT\" ."

set -o emacs
while [ 1 = 1 ] ; do
   sub1
# do something with the user input ...
done

regards

Bernd

2. What does run-level mean?

3. Problem with the read/print command in ksh

4. Cirrys Logic cards

5. ksh read command

6. console screen resolution

7. READ command in linux ksh

8. How can i run SLirp in Linux RedHat 6.0?

9. Ksh - read command

10. Getting a truly "raw" ksh read command

11. What's 'side effects' of Ksh built-ins?

12. ksh: 2 Q's, command completion & command history?

13. ksh, read reads files funny