问题
I have a script that randomly generates passwords, I have modified it to display in a GUI using zenity
. When I use the original script, I can produce random passwords of any length the user chooses (I tested with 50,000). Here's the code :
#!/bin/bash
number=10
echo "hello"
echo "Please enter your number: $number"
read newnumber
# read newnumber
[ -n "$newnumber" ] && number=$newnumber
MATRIX="0123456789<?/_+-!@#$%^&*>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
# Password will consist of standard characters.
LENGTH=$newnumber
#This variable can be changed for password lenth (need to try get zenity to let user choose that number)
while [ "${n:=1}" -le "$LENGTH" ]
# := is "default substitution" operator.
# So, if 'n' has not been initialized, set it to 1.
do
PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
# Very clever, but tricky.
# Starting from the innermost nesting...
# ${#MATRIX} returns length of array MATRIX.
# $RANDOM%${#MATRIX} returns random number between 1
# and [length of MATRIX] - 1.
# ${MATRIX:$(($RANDOM%${#MATRIX})):1}
# returns expansion of MATRIX at random position, by length 1.
# See {var:pos:len} parameter substitution in Chapter 9.
# and the associated examples.
# PASS=... simply pastes this result onto previous PASS (concatenation).
# to let zenity show the password being built one character at a time, uncomment the following line
# zenity --info --text="$PASS"
let n+=1
# Increment 'n' for next pass.
done
echo "$PASS"
(I have followed on from [another question][1]
[1]: Using a variable as another variable in a bash script? )
My problem is now that when try produce higher length passwords they wont display in the zenity --info
dialog box, anything over 30 is hit or miss. I have got it to display a 60 character by repeatedly running the script and choosing 60 each time but its not good enough to be so hit or miss, 9 times out of 10 it will produce less than 20 characters and struggles more the higher the length it has to generate. But only in zenity
Any help is of course greatly appreciated.
回答1:
I have found the answer and it's annoyingly simple... the characters </@#&*
would cause the generator to crash when used with zenity, but does anyone know why?
来源:https://stackoverflow.com/questions/25515362/zenity-info-dialog-is-unstable