LinuxQuestions.org
Help answer threads with 0 replies.
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 02-26-2004, 11:14 PM   #1
cadj
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: LinuxMint Elyssa
Posts: 373

Rep: Reputation: 32
bash scripting read from file


i have a file in the following format

John
Bob
Mary

how can i read the file, the then get the lines into variables such as $bob $john.
 
Old 02-27-2004, 06:50 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Code:
while read name
do
          echo $name
done < mytextfile
 
Old 02-29-2004, 10:42 PM   #3
rnturn
Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0), SuSE (10.x, 11.x, 12.2), Solaris (8-10), Tru64
Posts: 936

Rep: Reputation: 49
Well this works:
Code:
cat names.dat | while read NAME
do
    export ${NAME}=${NAME}
done
(It doesn't seem to work if you don't export the variable. Dunno why.)

Of course, just why you'd want shell variables named that way is a bit beyond me. :-)

Have fun,

Rick
 
  


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 Shell Scripting -- foreach file in folder??? AC97Conquerer Programming 11 07-06-2011 12:25 AM
Bash Scripting Empty file john8675309 Linux - Software 2 08-08-2007 04:05 PM
bash scripting - how to make config file? Neorio Programming 3 10-22-2004 06:39 AM
bash scripting - largest # file extension brian0918 Programming 3 06-16-2003 12:06 PM
bash scripting/batch file type thing antken Linux - General 2 01-22-2001 07:56 AM


All times are GMT -5. The time now is 11:04 PM.

Main Menu
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