我是 Linux 上 bash 的新手。我尝试简单地遍历目录中的文件,这些文件可以是链接或可执行文件。在链接上,我提到链接,在其他文件上,获取文件版本
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
它只对链接有效。 我将如何正确地做到这一点? 还有一些例子提到 [ ...] 而不是测试。有什么区别?
感谢任何有助于理解 bash 的提示!
最佳答案
使用 -n
避免回显后换行(或 printf
以获得更好的可移植性),并在单独的行上使用 readelf
命令或它被解释为 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
关于linux - Bash 中的 If then else 文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39408131/