Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-18-2005, 04:19 AM   #1
LQ Newbie
Registered: Sep 2004
Posts: 23

Rep: Reputation: 15
bash scripting

I am trying to write a script that assigns each line of a file to a shell array variable. The content of file is obtained with command below
(as root)
# fdisk -l | awk '/W95/ {print $1"\t\t"$7"\t\t"$8}' > anyfile
# export NUMLINES=`cat anyfile | wc -l` <- I got the number of lines
And here is the file content
/dev/hda1 W95 FAT32
/dev/hda3 Ext'd (LBA)
/dev/hda7 FAT32
/dev/hda8 FAT32
Which shows the my FAT partitons, Now, what I want to do is to assing each line to a shell array variable, like
$VAR[0] becomes /dev/hda1 W95 FAT32
$VAR[1] becomes /dev/hda3 Ext'd (LBA)
and so on.....
Is this possible, if so how?

Thanks for your advice....
Old 01-18-2005, 07:35 AM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I'm kinda partial to scriptable fdisk ( sfdisk ) so I used that to make file.txt
Then, the example uses ( var=`echo "var${n}"` ) to give the variable a number .....

#sfdisk -d /dev/hda > file.txt
cat ${a} |grep "start" |awk -F= '{print$4}' |\
while read i; do
let n=$n+1
var=`echo "var${n}"`
echo "$var is .. type ${i}"


Last edited by homey; 01-18-2005 at 08:33 AM.


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 scripting help (su ...) shwong Linux - General 1 11-02-2005 12:26 PM
Bash scripting pete1234 Programming 1 09-27-2005 01:48 AM
bash scripting vadon Linux - Newbie 6 05-10-2005 04:07 AM
need help with bash scripting rich2oo1 Programming 2 12-17-2003 12:50 PM
HELP with BASH scripting atwah Linux - Newbie 6 09-09-2003 01:10 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:55 PM.

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