LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-06-2010, 01:11 PM   #16
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115

Quote:
As someone pointed out in another thread (CTOP) there is no need for the IFS="" when each line is being read into a single variable, in this case $file.
Actually, the IFS is necessary. Try this:
Code:
read -r -d "" line <<< "   foo   "
echo "$foo"
IFS="" read -r -d "" line <<< "   foo   "
echo "$foo"
 
1 members found this post helpful.
Old 05-06-2010, 01:20 PM   #17
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by tuxdev View Post
Actually, the IFS is necessary. Try this:
Code:
read -r -d "" line <<< "   foo   "
echo "$line"
IFS="" read -r -d "" line <<< "   foo   "
echo "$line"
Thanks again tuxdev (and less CTOP and note to self to double check these things).

But I'm puzzled about why in the second case $line has a newline suffixed ... ?
 
Old 05-06-2010, 01:27 PM   #18
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Quote:
But I'm puzzled about why in the second case $line has a newline suffixed ... ?
The here-string syntax (<<< "") appends a newline to the end. Internally, it actually creates a here-doc and passes that in, like
Code:
IFS="" read -r -d "" line << EOF
   foo   
EOF
(Note that there's three spaces after "foo")
 
1 members found this post helpful.
Old 05-06-2010, 01:54 PM   #19
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Thanks for the clear explanation, tuxdev
 
  


Reply

Tags
bash, folder, programming, recursion, search


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to Bash | Need help with recursion. VauxhallVXR Programming 2 05-30-2009 06:47 PM
using recursion in bash script drkstr Linux - Software 4 07-09-2006 09:48 PM
Bash Local Variable Recursion With Array jshivers Programming 0 06-16-2006 05:31 PM
tar: '--no-recursion' option doesn't prevent recursion Earl Parker II Slackware 12 08-17-2004 03:49 AM
Writing bash script with recursion.. ray5_83 Programming 4 08-04-2004 06:44 PM


All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration