我正在编写一个函数来解析debian控制文件以获得包构建依赖性。下面是说的功能,它不起作用。
Debian控制文件仅由某些“标题”(即:Build-Depends:
)分隔,后面始终跟冒号(:
)。这有可能在同一行上没有Build-Depends
标题的多行上列出多个依赖项(否则我已经有了这个工作)。
我看到的具体问题是我从grep行收到“command not found”错误。 “命令”是控制文件中的单词/文本。我对脚本的了解有限。我用“google”将它拼凑在一起,所以我肯定会感激任何提示。
function FindDep ()
{
CheckVar=0
echo "Running Find Depend."
ControlPath=$TmpBuild/Deb-ConfFiles/$1/debian/control
cat $ControlPath | while read line ;
do
TempVar=`grep Build-Depends $line`
if [ "$TempVar" != "" ]; then
BuildDep=`sed s/Build-Depends://g $TempVar | sed s/Build-Depends-Indep\://g | grep -o '[a-z]*[-]*[a-z]*'`
CheckVar=1
elif [ $CheckVar == 1 ]; then
TempVar=`grep : $line`
if [ "TempVar" != "" ]; then
BuildDep="$BuildDep `sed s/Build-Depends://g $TempVar | sed s/Build-Depends-Indep\://g | grep -o '[a-z]*[-]*[a-z]*'`"
else
CheckVar=0
fi
fi
done
echo "Here is what is listed as dep for " $1 "--" $BuildDep
for y in $BuildDep; do
echo $y
IsInstalled="dpkg -s $y | grep Status"
if [ "$IsInstalled" == "" ]; then
echo "installing " $y
dpkg -i $y > /dev/null 2>&1
if [ $? -gt 0 ]; then
apt-get -f --force-yes --yes install >/dev/null 2>&1
fi
dpkg -i $y > /dev/null 2>&1
fi
done
echo "Ending Find Depend"
}
答案 0 :(得分:0)
首先转义引用变量的每一行,例如,转一下......
ControlPath=$TmpBuild/Deb-ConfFiles/$1/debian/control
到此:
ControlPath="$TmpBuild/Deb-ConfFiles/$1/debian/control"
这就是原因:
$ y=hello world
bash: world: command not found
$ y="hello world"
$ cat $y
cat: hello: No such file or directory
cat: world: No such file or directory
$ cat "$y"
cat: hello world: No such file or directory