Penguin
Penguin

Reputation: 71

Comparing SHA-512 Salted Hashes, displays filename during execution

Long story short during execution, i noticed that the "*" in the LIST somehow displays the name of the file i was executing. Is there anyway to let the code display "*" instead of displaying the filename ?

I am still a script newbie, could not think of any way. Please help ...

#!/bin/bash

LIST='W 2 v * %'
encr="Cd9AjUI4nGglIcP3MByrZUnu.hHBJc7.eR0o/v0A1gu0/6ztFfBxeJgKTzpgoCLptJS2NnliZLZjO40LUseED/"

salt="8899Uidd"
for i in $LIST
  do
   for j in $LIST
    do
    for k in $LIST
     do
      for l in $LIST
        do
        for a in $LIST
            do
            echo -n "$i$j$k$l$a "

   test=`mkpasswd -m SHA-512 $i$j$k$l$a -s $salt`
    if [ $test == $encr ] ; then
            echo " Password is: $i$j$k$l$a"
            exit
        fi
        done
       done
      done
    done
done

#error displaying *

Executed filename displayed

Upvotes: 0

Views: 209

Answers (1)

KamilCuk
KamilCuk

Reputation: 140880

The same as echo * expands the globulation * to the filenames in the current directory, the same way a=*; for i in $a; do echo $i; done will print paths in the current directory. You can read more about quotes and escaping at various places in the net.

You can use bash arrays to correctly quotes elements:

LIST=(W 2 v "*" %)
for i in "${LIST[@]}"; do

Notes:

  • Don't use backticks `, they are discouraged. Use $(..) instead.
  • Quote your variables expansions [ "$test" = "$encr" ] to protect from common bugs like this.
  • The == is a bash extension, use = to be portable.
  • The method for generating permutations of elements looks strange and is not scalable. Consider writing a function or using other method. Even (ab-)using bash extension brace expansion echo {W,2,v,"*",%}{W,2,v,"*",%}{W,2,v,"*",%}{W,2,v,"*",%}{W,2,v,"*",%} looks shorter.

Upvotes: 2

Related Questions