Skip to main content Snippets Groups Projects
public
Authored by avatar cleemy desu wayo

get_hash_test.sh

Edited
Embed
Share
  • Clone with SSH
  • Clone with HTTPS
  • get_hash_test.sh 664 B
    #!/bin/sh
    # written by cleemy desu wayo / Licensed under CC0 1.0
    #
    # test sha256sum & openssl
    #
    
    LANG=C   ; export LANG
    LC_ALL=C ; export LC_ALL
    
    get_hash() {
      if type sha256sum > /dev/null 2>&1; then
        echo 'mode: sha256sum' 1>&2
        sha256sum | awk '{print $1}'
      elif type openssl > /dev/null 2>&1; then
        echo 'mode: openssl' 1>&2
        openssl sha256 | awk '{print $NF}'
      else
        echo 'mode: error' 1>&2
        exit 1
      fi
    }
    
    get_hash_result=$(printf aaa | get_hash)
    printf 'result: %s\n' "$get_hash_result"
    
    if [ "x$get_hash_result" = "x9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0" ]; then
      echo 'ok'
      exit 0
    fi
    
    echo 'error'
    exit 1
    0% or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment