[HELP] Syntax Error in wordhash script

Forum rules
We don't support installations in VirtualBox, VMWare, qemu or others. We ignore posts about WINE, PlayOnLinux, Steam and Skype. We don't support btrfs, lvm, UEFI, side-by-side installations with GPT or dualboot with anything newer than Windows XP.
Google your problem first. Check the Wiki. Read the existing threads. It's okay to "hijack" an existing thread, yes! If your problem is not yet covered, open a new thread. To get the quickest possible help, mention the exact release codename in your post (uname -a is a good idea, too). Due to the lack of crystal balls, attach the output of lspci -nnk if you encounter hardware problems.
User avatar
davenull
Riesenpenis
Posts: 30
Joined: Wed Apr 29, 2015 4:31 pm
Location: Taranto, Italia

[HELP] Syntax Error in wordhash script

Unread post by davenull » Tue Dec 13, 2016 12:16 am

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.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: [HELP] Syntax Error in wordhash script

Unread post by pidsley » Tue Dec 13, 2016 1:16 am

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}

User avatar
davenull
Riesenpenis
Posts: 30
Joined: Wed Apr 29, 2015 4:31 pm
Location: Taranto, Italia

Re: [HELP] Syntax Error in wordhash script

Unread post by davenull » Tue Dec 13, 2016 1:54 am

thanx a lot, i used the cut solution :)

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: [HELP] Syntax Error in wordhash script

Unread post by pidsley » Tue Dec 13, 2016 3:12 pm

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/ -//')"

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: [HELP] Syntax Error in wordhash script

Unread post by wuxmedia » Tue Dec 13, 2016 3:47 pm

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
"Seek, and Ye shall find"
"Github | Chooons | Site"

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: [HELP] Syntax Error in wordhash script

Unread post by pidsley » Wed Dec 14, 2016 3:55 am

^ Well you're no fun. :/

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

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: [HELP] Syntax Error in wordhash script

Unread post by wuxmedia » Wed Dec 14, 2016 7:52 am

^ I thought it was quite funny. guess not.
"Seek, and Ye shall find"
"Github | Chooons | Site"

Post Reply