我有一个脚本,检查tar文件中是否存在文件,但是有些错误,因为它总是转到脚本的'else'部分.我很确定它不应该那样.
日期采用"Mon dd"格式(1月11日).
echo "enter date: \c"
read date
tarfile=`tar -tvf tarfile.tar | grep some_file | grep "$date"`
if [ -f "$tarfile" ]; then
echo "yes"
else
echo "no"
fi
Run Code Online (Sandbox Code Playgroud)
谢谢.
因为some_file它在tarfile.tar文件中,但您if正在检查它是否在文件系统上.
你可以像这样改变它
if tar –tf tarfile.tar some_file >/dev/null 2>&1; then
echo "tarfile.tar contains some_file"
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6971 次 |
| 最近记录: |