LinuxQuestions.org
Review your favorite Linux distribution.
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 11-28-2006, 08:37 AM   #1
Roger Krowiak
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 38

Rep: Reputation: 18
BASH: loading file to array


I have a question how to load content of text file into the array, where every member of array will present one line of the file.

First, let have file a.txt with following context:
Code:
this is line1
this is line2
When I did
Code:
my_list=($(<a.txt))
the first array member was 'this' and not 'this is line1' as I intended. So I've used the quotes:
Code:
my_list=("$(<a.txt)")
but the result was the whole file a.txt. So is there any way how to tell bash to delimit the context for array member by new line and not by space/tab?
 
Old 11-28-2006, 09:26 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
heh, just like busses, don't mention $IFS for months, then two come along at once.

http://www.linuxquestions.org/questi...d.php?t=505552
 
Old 11-28-2006, 09:48 AM   #3
Roger Krowiak
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by acid_kewpie
heh, just like busses, don't mention $IFS for months, then two come along at once.

http://www.linuxquestions.org/questi...d.php?t=505552
eh TY for link, once I've noted I should search for $IFS it was easy, so thank you very much. And your note about busses... thank you once again, for making me laugh :-))
 
  


Reply


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
Bash - File paths into an array Bat17 Programming 5 10-31-2006 03:56 AM
Bash script - how to reassemble file from array sixerjman Programming 11 08-25-2006 11:45 AM
Array Help in BASH! ?*%$ johnnybhoy67 Linux - Software 2 02-22-2006 10:39 AM
Bash files > array tigeraven Programming 3 12-13-2005 03:40 AM
[bash] Put words from file to array mispunt Programming 4 11-04-2004 10:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:42 PM.

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
Open Source Consulting | Domain Registration