我编写了以下 bash 脚本来查找驱动程序的名称,我会使它变得更好,但现在我只想知道为什么这个脚本不起作用?
#! /bin/bash
## the driver's name
drivername=$(lspci -vv -s $(lspci |grep -i ethernet| awk -F" " '{print $1}')| awk -F" " '/driver/ {print $5}')
checkout ()
{
lsmod > tmp.txt
if grep -i $1 "tmp.txt" > /dev/null ; then
echo "there's a driver"
else
echo "there's not any driver"
fi
}
ckeckout drivername ;
我已经测试了以下两个语句以确保调用该函数,但它们都没有起作用。
checkout $drivername
和
checkout drivername
那有什么问题?谢谢。
答案1
查看修正后的脚本:
#!/bin/bash
## the driver's name
drivername=$(lspci -vv -s $(lspci |grep -i ethernet| awk -F" " '{print $1}')| awk -F" " '/driver/ {print $5}')
checkout ()
{
lsmod > tmp.txt
if grep -i $drivername "tmp.txt" > /dev/null ; then
echo "there's a driver called: $drivername"
exit 0
else
echo "there's not any driver"
exit 1
fi
}
checkout $drivername;