I’m trying to extract directory location from location.txt and save it into an array, but it’s not looking good. When I execute the script,
i get this error
./test.sh: line 7: location.txt: No such file or directory bina@ajax $ ./test.sh
./test.sh: line 5: =/apps/IBM: No such file or directory
./test.sh: line 5: =/usr/home: No such file or directory
./test.sh: line 11: Unix_Array[0]: command not found
./test.sh: line 11: Unix_Array[1]: command not found
Here is my code
#!/bin/sh
counter=0
while read -r line; do
${Unix_Array[${counter}]}=$line;
let counter=counter+1;
done < location.txt
for ((i=0 ;counter > i; i++))
do
echo $(Unix_Array[$i])
done
and the text file
location.txt
/apps/IBM
/usr/home
/var/login
Can some one tell me what I did wrong?
I may have made one stupid error that i don’t know…(I’m really new in UNIX)
Thanks in advance
Just remove your first
${}on${Unix_Array[${counter}]}=$line;because you just want to assign to the array, not assign and retrieve its value, your fixed script would be like this: