Skip to content

Instantly share code, notes, and snippets.

@thomasjo
Created April 15, 2014 14:10
Show Gist options
  • Save thomasjo/10735888 to your computer and use it in GitHub Desktop.
Save thomasjo/10735888 to your computer and use it in GitHub Desktop.
Command substitution issue?
# This doesn't work together with bats stub as defined in ruby-build
compute_sha2() {
if type shasum &>/dev/null; then
local output="$(shasum -a 256 -b)"
echo "${output% *}"
elif type openssl &>/dev/null; then
local output="$(openssl dgst -sha256)"
echo "${output##* }"
elif type sha256sum &>/dev/null; then
local output="$(sha256sum --quiet)"
echo "${output% *}"
else
return 1
fi
}
# This works in bats when `shasum` is stubbed, but breaks against
# the real binary because the output is "noisy"...
compute_sha2() {
if type shasum &>/dev/null; then
shasum -a 256 -b
elif type openssl &>/dev/null; then
local output="$(openssl dgst -sha256)"
echo "${output##* }"
elif type sha256sum &>/dev/null; then
local output="$(sha256sum --quiet)"
echo "${output% *}"
else
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment