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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cannot read a file with read(fd, buffer, buffersize) function naranja18she High Level Programming 3 06-12-2009 02:39 PM
Can I use read to read content of a variable nmalencia Shell Programming and Scripting 9 03-26-2009 06:58 AM
read is not pausing to read davegerdt Shell Programming and Scripting 3 04-07-2008 11:20 AM
ls while read loop - internal read picking up wrong input dkieran Shell Programming and Scripting 2 05-14-2007 04:02 PM
read line and read next ariuscy UNIX for Dummies Questions & Answers 7 09-21-2005 08:04 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2009
raphinou raphinou is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
read and IFS

Hi,

This is out of curiosity:
I wanted to extract year, month and date from a variable, and thought that combining read and IFS would help, but this doesn't work:

echo "2010 10 12" | read y m d

I could extract the parts of the date when separated by a -, and setting IFS in a subshell:
r=$(echo '2010-10-12' |(IFS='-'; read y m d; echo $y $m $d))

Any explanation why the first doesn't work?

Thanks

Raphaël
  #2 (permalink)  
Old 10-12-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,119
In ksh:

Code:
echo "2010 10 12" | read y m d

In Bash (and newer ksh's):

Code:
read y m d <<< "2010 10 12"

Using IFS:

Code:
echo '2010-10-12'  | IFS='-' read y m d
echo $y $m $d
2010 10 12

IFS='-' read y m d <<<  "2010-10-12"
echo $y $m $d
2010 10 12

  #3 (permalink)  
Old 10-12-2009
raphinou raphinou is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
Thanks scottn for the clarifications.
Any idea why read <<< behaves differently from echo "" | read

Raph
  #4 (permalink)  
Old 10-12-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,119
Hi.

The bash manpage describes <<< as a "here string", a variant of a here document.

echo ... | read ... is just a plain old pipe.
Reply

Bookmarks

Tags
bash, ifs

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0