我想输入一个命令输出,其中包含几个管道。我编写的代码如下所示:
curl https://www.gentoo.org/downloads/signatures/ | grep 0x | cut -d '>' -f3 | cut -d '<' -f1 | while read line; do
gpg --recv-keys $line
tempfingerprint= `gpg --fingerprint $line | head -2 | tail -1 | cut -d'=' -f2 | cut -d ' ' -f2-12`
echo $tempfingerprint当我试图回显结果(最后一行代码)时,我会收到一条错误消息。我调试了它,这是调试日志:
336 + head -2
336 + tail -1
336 + cut -d= -f2
336 + cut -d ' ' -f2-12
336 + gpg --fingerprint 0xBB572E0E2D182910
36 + tempFingerPrint= 36 + 13EB BDBE DE7A 1277 5DFD B1BA BB57 2E0E 2D18 2910
./gentoo-stage.sh: line 36: 13EB: command not found如何将所有指纹分配给变量?
发布于 2016-03-18 15:48:54
在=之后有一个空间
tempfingerprint= `gpg --fingerprint $line | head -2 | tail -1 | cut -d'=' -f2 | cut -d ' ' -f2-12`
# ^这就是导致错误的原因,把它移除。
另外,它不是必需的,但是您应该更喜欢"$(...)"而不是`...`,因为它更安全,更容易阅读:
tempfingerprint="$(gpg --fingerprint $line | head -2 | tail -1 | cut -d'=' -f2 | cut -d ' ' -f2-12)"一般来说,总是引用你的变量展开。
https://stackoverflow.com/questions/36088588
复制相似问题