Pompy
Pompy

Reputation: 41

readlink unable to take path names mentioned in a file

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?

Upvotes: 1

Views: 202

Answers (1)

Jared Rummler
Jared Rummler

Reputation: 38131

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

Upvotes: 1

Related Questions