I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array.
plz help me how to accomplish this.
Thanks in advance.
I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array.
plz help me how to accomplish this.
Thanks in advance.
#! /bin/bash
i=0
for x in /home/sam/*.dat
do
arr[$i]=$x
i=$(($i+1))
done
echo ${arr[@]}
Hello Bala ,
In addition to your solution , i would like to add the increment part of index , can also be done below .
((i+=1))
Or just ((i++))
Or just use:
FILES=( /home/sam/*.dat )
echo "${FILES[@]}"