[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Tackling parameter expansion in functions
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] Tackling parameter expansion in functions |
Date: |
Fri, 12 Feb 2016 13:25:38 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Feb 12, 2016 at 07:14:18PM +0100, Richard Taubo wrote:
> Something like:
> ---------------------
> Test2() {
> if [ ???$1??? == "this" ]; then
> word=$("< /dev/urandom tr -dc _A-Z | head -c${1:-7}
> 2>/dev/null;echo;")
> printf "$word"
> fi
> }
>
> Test2 "this"
> ---------------------
In English?
Are you trying to generate a random password? Just install something like
https://sourceforge.net/projects/pwgen/ instead of doing this /dev/urandom
nonsense. Hell, it's even packaged for most Linux distributions.
I think you found a piece of code in another script, and copied it for
your own script, without understanding what it means.
head -c${1:-7}
means "Show the first $1 characters, or the first 7 characters if no
argument was given."
You can't use $1 to be both "this" and "number of characters". You would
need to use a separate argument for the "number of characters".
I have utterly no idea why you are comparing $1 to the string "this".