Page 1 of 1

[HELP] Syntax Error in wordhash script

Posted: Tue Dec 13, 2016 12:16 am
by davenull
Hi, I don't know if this is the right section, anyway you can move it.
I write this script that hash a single word in some hashes, but I see some syntax errors. I don't know why. This is the source code:

Code: Select all

#!/bin/bash
## wordhasher 0.1
## davenull - [email protected]
## http://www.davenull.altervista.org
## Data Creazione: 12 Dicembre 2016
## Questo script trasforma una parola in svariati hash senza
## effettuarne il salt, cosa che normalmente avviene in CMS
## come Wordpress. Basta lanciare il programma seguito dalla
## parola da hashare.
echo "wordhasher 0.1"
echo "davenull - [email protected]"
echo "http://www.davenull.altervista.org
parola=$1
md5hash=$2
shahash=$3
sha1hash=$4
sha224hash=$5
sha256hash=$6
sha384hash=$7
sha512hash=$8

echo "Gli hash generati della parola" $parola "sono:"

md5hash="$(echo -n $parola | md5sum)"
echo "md5:" $md5hash

shahash="$(echo -n $parola | shasum)"
echo "sha:" $shahash

sha1hash="$(echo -n $parola | sha1sum)"
echo "sha1:" $sha1hash

sha224hash="$(echo -n $parola | sha224sum)"
echo "sha224:" $sha224hash

sha256hash="$(echo -n $parola | sha256sum)"
echo "sha256:" $sha256hash

sha384hash="$(echo -n $parola | sha384sum)"
echo "sha384:" $sha384hash

sha512hash="$(echo -n $parola | sha512sum)"
echo "sha512:" $sha512hash
Can you help me to understand the error.
I want to delete the last two letters in the hashes too, and the "cut" command can't help me.

Re: [HELP] Syntax Error in wordhash script

Posted: Tue Dec 13, 2016 1:16 am
by pidsley
Paste the script into http://www.shellcheck.net/. This will show you exactly where the syntax error is.

This line has no close quote:

Code: Select all

echo "http://www.davenull.altervista.org
Should be:

Code: Select all

echo "http://www.davenull.altervista.org"
You can do something like this to only show the first part of each line:

Code: Select all

shahash="$(echo -n $parola | shasum | cut -d' ' -f1)"
or awk:

Code: Select all

sha256hash="$(echo -n $parola | sha256sum | awk '{print $1}')"
or if you know you always want to trim two characters at the end:

Code: Select all

echo "sha512:" ${sha512hash::-2}

Re: [HELP] Syntax Error in wordhash script

Posted: Tue Dec 13, 2016 1:54 am
by davenull
thanx a lot, i used the cut solution :)

Re: [HELP] Syntax Error in wordhash script

Posted: Tue Dec 13, 2016 3:12 pm
by pidsley
More code, because I'm bored.

bash delete " -" from the end of a string:

Code: Select all

echo "md5:" ${md5hash% -}
bash delete everything after the last space from the end of a string:

Code: Select all

echo "md5:" ${md5hash% *}
bash replace " -" in a string with nothing:

Code: Select all

echo "sha512:" ${sha512hash/ -/}
sed replace " -" in a string with nothing:

Code: Select all

sha384hash="$(echo -n $parola | sha384sum | sed 's/ -//')"

Re: [HELP] Syntax Error in wordhash script

Posted: Tue Dec 13, 2016 3:47 pm
by wuxmedia
If it's resolved - please mark the thread [solved] or [fixed] or <resolved> or whatever, (edit your first post) otherwise we'll keep rewriting and feature creeping your code until it can check for emails.. :P

Re: [HELP] Syntax Error in wordhash script

Posted: Wed Dec 14, 2016 3:55 am
by pidsley
^ Well you're no fun. :/

I learned a bunch of new things playing with this, and I thought others might find them useful.

Re: [HELP] Syntax Error in wordhash script

Posted: Wed Dec 14, 2016 7:52 am
by wuxmedia
^ I thought it was quite funny. guess not.