ao-mud is a spellbook of well-commented atomic bash scripts that each do one thing. we are building semantic building blocks for an autonomously-evolving digital spellcasting language.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
874 B

#!/bin/sh
# The Hash Spell
#
# This powerful spell allows you to compute the CRC-32 hash of a text file, including its filename. Simply provide
# the path to the file as an argument, and the spell will do the rest. The resulting hash will be displayed on the
# command line.
if [ "$#" != 1 ]; then
echo "Usage: hash file"
exit 1
fi
# Get the directory where the script is being called from
script_dir="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
# Get the file name specified as an argument
file_name="$1"
# Concatenate the script directory and the file name to get the full file path
file="$script_dir/$file_name"
if [ ! -f "$file" ]; then
echo "Your spell fizzles. There is no file."
exit 1
fi
echo $file
# Compute the CRC-32 hash
crc=$(cksum "$file" | awk '{print $1}')
# Convert the hash to hexadecimal and display it
printf "0x%x\n" "$crc"