$1 is the first argument given to bash script, there are nine of them $1-$9. It works, I can give any number between 1-32, and it outputs as many characters. Thank's for reply!
Okay, step by step:
Code: Select all
if [ $# -eq 0 ]; then
< /dev/urandom tr -dc [:graph:] | head -c${1:-8};echo;
exit 0
This checks the number of given arguments, if none, it uses default, which I set to 8 character random string.
I think this is quite self explanatory, password which is 0 bytes lenght, is not very useable.
Code: Select all
elif (( $1 < 33 )); then
< /dev/urandom tr -dc [:graph:] | head -c${1:-$1};echo;
exit 0
And this, as I explained, generates random string as long as the first argument between 1-32.
Code: Select all
else
< /dev/urandom tr -dc [:graph:] | head -c${1:-32};echo;
exit 0
fi
This was meant to restrict output to 32 characters even if bigger number is given as first argument. But does not work, and I do not understand why.