LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 01-18-2005, 05:19 AM   #1
fnoyan
LQ Newbie
 
Registered: Sep 2004
Posts: 23

Rep: Reputation: 15
bash scripting


Hi
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, 08:35 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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 .....
Code:
#!/bin/bash

#sfdisk -d /dev/hda > file.txt
n=0
a=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}"

done

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


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


All times are GMT -5. The time now is 04:04 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