Linux 脚本don';抽提焦油

Linux 脚本don';抽提焦油,linux,shell,Linux,Shell,我有这个脚本外壳,它提取并安装libpcap库 #!/bin/sh PATH=/usr/src wget=/usr/bin/wget tar=/bin/tar echo "###############" echo "INSTALL LIBPCAP" echo "###############" $tar -xvf libpcap-1.3.0.tar.gz cd libpcap-1.3.0 ./configure --prefix=/usr make && make insta

我有这个脚本外壳,它提取并安装libpcap库

#!/bin/sh
PATH=/usr/src
wget=/usr/bin/wget
tar=/bin/tar

echo "###############"
echo "INSTALL LIBPCAP"
echo "###############"
$tar -xvf libpcap-1.3.0.tar.gz
cd libpcap-1.3.0
./configure --prefix=/usr
make && make install
当我执行它时,我有这个错误

tar (child): gzip: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
/bin/tar: Child returned status 2
/bin/tar: Error is not recoverable: exiting now
./install.sh: 14: cd: can't cd to libpcap-1.3.0

您已经将路径更改为/usr/src,所以当tar尝试执行gzip时,它无法找到它,因为它只在/usr/src中查找。您需要将gzip的位置添加到PATH(以及configure脚本将要调用的每个工具以及make的位置),或者显式地调用它,而不是让tar调用它,或者(最佳选择),不修改PATH。如果您坚持要更改路径,请尝试
PATH=/usr/src:/usr/sbin:/usr/bin:/sbin:/bin
PATH=/usr/src:$PATH
,但实际上,最好不要使用它,而且在其中放入名为
src
的目录非常奇怪。

如果您想将
/usr/src
添加到
PATH
变量中,则更好的方法如下

PATH="$PATH:/usr/src"
要使脚本从任何目录路径运行,请使用一个单独的变量,该变量保存源文件路径的绝对路径,如下面脚本中使用的
file\u path
变量

#!/bin/sh
PATH="$PATH:/usr/src"
wget=/usr/bin/wget
tar=/bin/tar
file_path="/path/to/source-files"

echo "###############"
echo "INSTALL LIBPCAP"
echo "###############"
$tar -xvf $file_path/libpcap-1.3.0.tar.gz
cd $file_path/libpcap-1.3.0
./configure --prefix=/usr
make && make install

在处理gzip tar时,您应该显式地传递选项
-z
,因此您的代码应该类似于:


$tar-xzvf libpcap-1.3.0.tar.gz

的可能副本似乎您的系统上缺少gzip或sh找不到它。检查gzip是否存在,如果存在,检查它是否在SH的搜索路径中(您可以在脚本中使用“echo$path”,并查看gzip所在的文件夹是否在路径中)这是$path/root/.embulk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/usr/games:/usr/local/games的内容如果我不使用path,问题仍然存在