【发布时间】:2011-01-15 09:12:37
【问题描述】:
在 shell 脚本中运行外部实用程序时的最佳做法是什么。例如,如果我想在多个脚本中运行“gzip”以确保使用特定的 gzip 二进制文件,我应该将二进制文件的完整路径设为变量并在整个脚本中使用该变量吗?
GZIP=/home/me/bin/gzip
$GZIP somefile
$GZIP anotherfile
或者更好的做法是硬编码每次调用二进制文件的路径?
/home/me/bin/gzip somefile
/home/me/bin/gzip anotherfile
还是设置和依赖路径更好?
PATH=/home/me/bin:$PATH
gzip somefile
gzip anotherfile
我没有以 root 身份运行脚本,因此可维护性和可移植性比用户安全更重要。
【问题讨论】: