I have a (bash) script I would like to run on two different computers, one is OpenBSD with the program sha256, the other is Ubuntu with sha256sum. What is the best/standard practice to allow the script to handle both cases? 
Note that for sha256 vs sha256sum, the other options into the program wouldn't need to be change, but for a different choice of programs, such as wget vs. curl, the other parameters would change too (e.g. wget vs. curl -O). Therefore, the best answer would allow different command line parameters as well depending on which program is available.
One way of fixing the program is to use a variable that changes depending on the exit status of command, hash, or type, as per this SO question
e.g.
SHA_PROGRAM=sha256
command -v "$SHA_PROGRAM"
# If the exit status of command is nonzero, try something else 
if [ "$?" -ne "0" ]; then
    command -v "sha256sum"
    if [ "$?" -ne "0" ]; then
        printf "This program requires a sha256 hashing program, please install one\n" 1>&2
        exit 1
    else
        SHA_PROGRAM=sha256sum
    fi 
fi
$SHA_PROGRAM $MYFILE
But, that way seems a little verbose to me, not to mention the nested if-statement issue.
It could be generalized a bit by using an array of possible commands:
declare -a POSSIBLE_COMMANDS=("sha256" "sha256sum")
SHA_PROGRAM=""
for $OPT in "${POSSIBLE_COMMANDS[@]}"
do
    command -v "$OPT"
    # if the exit status of command is zero, set the command variable and exit the loop
    if [ "$?" -eq "0" ]; then
        SHA_PROGRAM=$OPT
        break
    fi
done 
# if the variable is still empty, exit with an error    
if [ -z "$SHA_PROGRAM" ]; then
    printf "This program requires a sha256 program. Aborting\n" 1>&2
    exit 1
fi
$SHA_PROGRAM $MY_FILE
That way would work too I believe, but I am hoping to get advice from a more experienced, better bash programmer, in case I am missing some better solution (perhaps a clever use of the || operator?).

opensslinstalled, you can just useopenssl sha256in both places and not worry about picking an os-specific program.openssl sha256looks good for generating the hash. Is there a related way to check a file with the hashes listed in it. I.e. equivalent tosha256 -c FILE?for $OPT in ...won't work, remove$. And it's superfluous to use$?just for checking success/failure, simply writeif command -v "$OPT"; then.