readlink unable to take path names mentioned in a file

174 Views Asked by At
while
    read -r line 
        do  
           readlink -f $line > a.txt 
done < $1

I have a file which contains 30 symbolic destination pathnames passed by $1. I want to read this file line by line and wants to save ls results of each path in a file a.txt. The problem coming is that its only taking last path name mentioned in $1. Its ignoring upper 29 lines. Why?

1

There are 1 best solutions below

4
On BEST ANSWER

Change

readlink -f $line > a.txt

to

readlink -f "$line" >> a.txt

The >> appends to a file or creates the file if it doesn't exist.

The > overwrites the file if it exists or creates it if it doesn't exist.

https://serverfault.com/a/196735