The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-04-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
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
And it gave me this.

[~/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
Reply With Quote
Forum Sponsor
  #2  
Old 08-04-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
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.
Reply With Quote
  #3  
Old 08-04-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
See read command for more info.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0