gpt4 book ai didi

unix - 可以在 If 语句中使用 tar -xvf 返回 true 或 false

转载 作者:行者123 更新时间:2023-12-05 01:28:33 25 4
gpt4 key购买 nike

我知道我听起来可能很奇怪,但我想知道我是否可以对某些文件执行 if [tar -xvf] 并返回 true 或 false 。

如果打包成功,我需要在文件中写入一些内容,如果不成功,则在同一文件中写入其他内容。

有点像

if[ find . -maxdepth 1 -name "*.tar" -exec tar -xvf {} ] ; then
echo " Untar Successful"> test.txt
else
echo "Untar Not Successful"> test.txt

如果我能做些什么来实现这个,请告诉我

最佳答案

EXIT STATUS
The tar utility exits 0 on success, and >0 if an error occurs.

你可以像这样检查错误

if [ $? -ne 0 ]; then

$在哪里?是最近的前台管道退出状态。

关于unix - 可以在 If 语句中使用 tar -xvf 返回 true 或 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6853022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com