-1

我正在编写一个函数来解析 debian 控制文件以获取包构建依赖项。下面是所说的功能,它不起作用。

Debian 控制文件仅由某些“标题”(即:)分隔,这些“标题”Build-Depends:后面总是跟一个冒号(:)。这导致多个依赖项可能被列在多行上,而同一行上没有Build-Depends标题(否则我已经可以使用它了)。

我看到的具体问题是我从 grep 行收到“找不到命令”错误。“命令”是控制文件中的文字/文本。我对脚本的了解有限。我用“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"
}
4

1 回答 1

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
于 2012-04-09T13:57:03.013 回答