3 ms·
Why not use the -c option? Especially if you're using Bash or Zsh which has "here-strings": checksum() { hash="$1" file="$2" sha256sum -c
by nerdponx 4y ago
Why not use the -c option? Especially if you're using Bash or Zsh which has "here-strings":
checksum() {
hash="$1"
file="$2"
sha256sum -c <<< "${hash} ${file}"
}
Or if you need to use a POSIX-ish shell:
checksum() {
hash="$1"
file="$2"
printf '%s %s' "$hash" "$file" | sha256sum -c
}
Of course you can add a `--binary` option (uses '%s *%s' instead of '%s %s'), options to use different hash functions, etc.
I also think it's weird to use `alias` inside a function, instead of just using a parameter to store the name of the program to execute.
- gavinuhma 4y agoGreat point on alias, thanks. I think that was a relic of an older iteration. I'll work through these suggestions. Appreciate it. Feel free to send a PR if you want. For the here string I think that won't work because the file isn't being saved locally, it's just being piped (so $2 is a URL). I can't do the usual `shasum -c <<< "132e320edb0027470bfd836af8dadf174e4fee00 install.sh" which takes a local filename but not the file content. As far as I could tell anyway. I'll try it some more