gpt4 book ai didi

bash - 删除 (STDIN)= BASH 中的标签

转载 作者:行者123 更新时间:2023-11-29 09:23:51 27 4
gpt4 key购买 nike

我在使用 (STDIN) 时遇到问题

我编写了以下 bash 脚本来计算字符串的 sha1 哈希值,并以大写格式输出它,以便复制到 plist 文件中。

这是脚本:-

#!/bin/bash        

echo 'Enter String :-';

read temp_var1; #Read string

hash=$(echo -n $temp_var1 | openssl sha1); #Copy hash into variable $hash

uphash=$(echo $hash | tr '[:lower:]' '[:upper:]';); #Convert hash to Upper-case

echo 'Below is the UPPERCASE SHA1 Hash of your string';

echo ' </yourHash>'$uphash'</yourHash>'; #Echo formatted string

整个脚本在解决一个关键问题时效果很好。输出不是我想要的。例如输入

Hello, World!

我想得到以下输出:-

Below is the UPPERCASE SHA1 Hash of your string
</yourHash>0A0A9F2A6772942557AB5355D76AF442F8F65E01</yourHash>

相反,我得到的是:-

Below is the UPPERCASE SHA1 Hash of your string
</yourHash>(STDIN)= 0A0A9F2A6772942557AB5355D76AF442F8F65E01</yourHash>

我的问题是。我如何删除此 (STDIN)= 标签及其后面的空格?

非常感谢您提供的任何帮助。

海市蜃楼

最佳答案

您可以像这样使用参数替换将其从前面剥离:

a="(STDIN)= 0A0A9F2A6772942557AB5355D76AF442F8F65E01"
b=${a#*= } # Strip up to "=" sign
echo $b
0A0A9F2A6772942557AB5355D76AF442F8F65E01

我怀疑 openssl 有一个选项可以阻止它生成“(STDIN)”部分,但我的没有这样做。

如果你想了解更多关于这类的东西,看看here.

关于bash - 删除 (STDIN)= BASH 中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906330/

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