gpt4 book ai didi

linux - shell 脚本 - 验证 sha256sum

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:04:21 24 4
gpt4 key购买 nike

我正在编写用于自动下载文件的脚本。作者提供了校验和。所以我想在脚本中自动验证这些:

if ! [[ $(sha256sum  -c latest-12.tar.bz2.sha256 < latest-12.tar.bz2) = 'latest-12.tar.bz2: OK']]; then
echo "Fehler im Download"
exit 1
fi

输出:

syntax error in conditional expression: unexpected token `;' 
syntax error near `;'
`if ! [[ $(sha256sum -c latest-12.tar.bz2.sha256 < latest-12.tar.bz2) = 'latest-12.tar.bz2: OK']]; then'

这是怎么回事?

最佳答案

正如评论中提到的,在结束 ]] 之前缺少一个空格。

实现目标的更好方法是使用:

if ! sha256sum --quiet -c latest-12.tar.bz2.sha256; then 
echo "Fehler im Download"
exit 1
fi

或简单地

sha256sum --quiet -c latest-12.tar.bz2.sha256 || { echo "Fehler im Download"; exit 1; }

这两个命令都假定 latest-12.tar.bz2.sha256 中指示的文件路径与您运行命令的位置相匹配。

关于linux - shell 脚本 - 验证 sha256sum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47176674/

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