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