![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| check input = "empty" and "numeric" | geoffry | Shell Programming and Scripting | 6 | 12-13-2007 02:12 AM |
| Maximum input file size in "Diff" Command | Neeraja | UNIX for Dummies Questions & Answers | 1 | 01-17-2007 07:09 AM |
| Giving "read" from standard input a timeout. | rello | Shell Programming and Scripting | 10 | 07-08-2005 05:54 AM |
| The "read" command | 435 Gavea | UNIX for Advanced & Expert Users | 16 | 11-19-2003 10:51 AM |
| how to request a "read" or "delivered" receipt for mails | plelie2 | Shell Programming and Scripting | 1 | 08-06-2002 12:26 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Breaking input with "read" command
In this post, Perderabo's script says
echo 05/06/25 14:15:56 | IFS=" /:" read Y1 M1 D1 h1 m1 s1 which, if I am not wrong, will break the input into Y1, M1 et al. I tried the following in my code Code:
#! /bin/ksh # per.sh typeset -R2 HOUR=00 typeset -R2 MIN=00 typeset -R2 SEC=00 TIME=09:12:23 echo $TIME | IFS=" :" read HOUR MIN SEC echo $HOUR$MIN$SEC echo $TIME [~/temp]$ ksh per.sh 000000 09:12:23 [~/temp]$ uname -a Linux staci21 2.4.21-27.ELsmp #1 SMP Wed Dec 1 21:59:02 EST 2004 i686 i686 i386 GNU/Linux Any idea what is wrong in my code ? Am I missing something ? Thanks, Vino |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
it works fine on Solaris, but breaks on RH.
the "problem" is read-ing the vars off the 'pipe' - reading off the pipe creats a child process. Once read-ing is done, child process exits - no vars get exported to the parent. Just as an illustration: Code:
#! /bin/ksh
# per.sh
typeset -R2 HOUR=00
typeset -R2 MIN=00
typeset -R2 SEC=00
TIME=09:12:23
echo "${TIME}" > /tmp/vino.txt
IFS=" :" read HOUR MIN SEC < /tmp/vino.txt
echo $HOUR$MIN$SEC
echo $TIME
Last edited by vgersh99; 08-04-2005 at 09:03 AM. |
|
#3
|
||||
|
||||
|
See read command for more info.
|
||||
| Google The UNIX and Linux Forums |