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.