Reputation: 1979
I am new to bash on Linux. I try to simple iterate over files in a directory which can be links or executeables. On Links I mention Link and on other files get file version
for i in *; do
if test -f "$i"
then
if test -L "$i"
then
echo "File $i,Link"
else
echo "File $i," readelf -a -W $i |grep SONAME
fi
fi
done
it only workes on the links. How would I do it correctly ? Also some examples mention [ ...] instead of test. What is the difference ?
Thanks for any hint that helps understanding bash !
Upvotes: 0
Views: 68
Reputation: 140266
use -n
to avoid newline after echo (or printf
for better portability), and use the readelf
command on a separate line or it is interpreted as an argument of echo
.
for i in *; do
if test -f "$i"
then
if test -L "$i"
then
echo "File $i,Link"
else
printf "File $i,"
readelf -a -W $i |grep SONAME
fi
fi
Upvotes: 2