sharen

A bash script to rename files using its sha256 hash number, no error trapping or anything yet.

#!/usr/bin/bash

function procfile {
	filename=$1
	filesum=$(sha256sum -b $filename)
	filesha=$(echo $filesum | cut -d " " -f1)
	# filesha=${filesum%-*}
	extension="${filename##*.}"
	newfilename=$filesha"."$extension
	mv $filename $newfilename
}

function showhelp {
	echo "sharen or $1, is a program designed to rename a specified file"
	echo "to its sha256 hash as its filename, preserving the file exitension"
	echo
	echo "The syntax"
	echo
	echo "	sharen filename"
	echo "		filename being the name of the file to process."
	echo
}

if [ -f "$1" ]; then
	procfile $1
else
	showhelp $0
fi