I was writing up a bash script to collect hardware information of each servers. But at some portion of the script I am unable to print values of variable that is given multiple times in a single echo command
#!/bin/bash
NO=$(df -hT | grep ext | wc -l)
for i in $(seq 1 $NO);do export PART$i=$(df -hT | grep ext | head -$i | tail -1 | awk '{print $1}'); done
echo "Total $NO ext partitions found"
for i in $(seq 1 $NO);do echo "Ext Partition$i is ${PART$i} ";done
In my system, I have two ext partitions, so variable $NO would store value 2.
The output I expect and wanted is as follows:
Total 2 ext partitions found
Ext Partition1 is /dev/sda7
Ext Partition2 is /dev/sda8
But I am having trouble printing "$PART$i" as expected. Right now I am getting error for "for loop" in last line.
# /root/disk.sh
Total 2 ext partitions found
/root/disk.sh: line 5: Ext Partition$i is ${PART$i} : bad substitution
Can you tell me how to correctly invoke and echo the value of PART1 and PART2 in last for loop?.