Bash:从文件中读取包名时出现的$相关问题

时间:2016-12-15 08:24:40

标签: bash ubuntu apt-get

我有一个存储APT包名称的文件GL.PushMatrix(); // Rotate the car GL.Translate(x, y, z); //x=0, y=0, z=0 GL.Rotate(ori, 0, 1, 0); // ori=90 // ... // Material and lighting code // ... foreach (var group in file.G) { GL.PushMatrix(); if (group.name == "wheel_rf") { float xTmp, yTmp, zTmp; xTmp = yTmp = zTmp = 0; int count = 0; // read group's faces foreach (var f in group.F) { // read face's vertices foreach (var v in f.V) { yTmp += v.Y; zTmp += v.Z; xTmp += v.X; count++; } } yTmp /= count; zTmp /= count; xTmp /= count; GL.Translate(xTmp, yTmp, zTmp); GL.Rotate(this.wheelAngle, 1, 0, 0); GL.Translate(-xTmp, -yTmp, -zTmp); } // draw faces for each group GL.Begin(file.PrimitiveType); foreach (var face in group.F) { GL.TexCoord2(face.VT[0]); GL.Normal3(face.VN[0]); GL.Vertex3(face.V[0]); GL.TexCoord2(face.VT[1]); GL.Normal3(face.VN[1]); GL.Vertex3(face.V[1]); GL.TexCoord2(face.VT[2]); GL.Normal3(face.VN[2]); GL.Vertex3(face.V[2]); } GL.End(); GL.PopMatrix(); } GL.PopMatrix(); - 每行一个包。 我通过以下方式使用此文件的内容:

apt.list

除了包名称为例如

的情况外,一切正常
entries=`cat apt.list`
for entry in $entries
do
  apt-get install $entry
done

如何正确解释包含$的条目?

1 个答案:

答案 0 :(得分:0)

不要解析cat输出,在文件周围使用适当的循环来解析每一行输出。

#!/bin/bash

while IFS= read -r line
do
    apt-get install "$line"
done<apt.list