-
-
Save paulgibbs/9e3207fd912f84935d9bc888ae08beaa to your computer and use it in GitHub Desktop.
WHSHASCRIPT="sha1sum" && (type sha1sum >/dev/null 2>&1 || WHSHASCRIPT="shasum") |
@henrywright Not quite true. If you simply that and do something like type sha1sum >/dev/null 2>&1 || echo "this will get printed"
, then that message will get printed. You should be able to test this and see on any Unix-like shell (just replace sha1sum with some made-up app name that you don't have).
Oh, I've got this. From memory, those curly brackets evaluate inside another (nested) shell, and I bet that value is being set inside that transient shell.
Removing the curly brackets make it behave like I think it should. I might need to replace with square brackets; next step to figure out how to get it working in my script!
The subshell theory is a good shout @paulgibbs. Try exporting the WHSHASCRIPT
variable to make it also available in the child shell
Also I agree my original guess is wrong. I assumed you had sha1sum
on your Mac, which of course you don't.
For the record, I've iterated on this approach; I was using this to find which sha-1 tool exists (mac vs most linux) - and then run it - but i've switched approach to using the openssl
program, like this: cat %2$s | openssl dgst -sha1 -binary | xxd -p
Only problem I can see with using that program is how can you guarantee the binary is in the user's path?
If the
type sha1sum >/dev/null 2>&1
command succeeds,WHSHASCRIPT="shasum"
will never be executed.I may be wrong but you seem to be redirecting the output of
type sha1sum
into the black hole/dev/null
and sending errors toSTDOUT
. My guess is that is all succeeding andWHSHASCRIPT="shasum"
is never run.