1

I want to enter an output of command with a few pipes to var. The code I wrote looks like this:

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

cut when I try to echo the results (last code line) I get an error message. I debugged it, and this is the debug log:

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

How can I assign the all fingerprint to the variable?

1 Answer 1

2

There's a space after the =:

tempfingerprint= `gpg --fingerprint $line | head -2 | tail -1 | cut -d'=' -f2 | cut -d ' ' -f2-12`
#               ^

That's what causing the error, remove it.

Also, it's not required, but you should prefer "$(...)" over `...`, as it's safer and easier to read:

tempfingerprint="$(gpg --fingerprint $line | head -2 | tail -1 | cut -d'=' -f2 | cut -d ' ' -f2-12)"

And, in general, always quote your variable expansions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.