Hey Gurus,
I'm trying to write a bash script. There are 4 arrays: base10 base16 base62 base70.
I want to match an array based on two digits provided by argument $1.
e.g. getArray 70 would select base70
I've looked at substitutions, and {parameter,bash,brace} expansions.
This substitution look possible ${foo/%from/to} (replace suffix) but that led me nowhere.
This looks like it should be *so easy*,
Amy takers?
Mike Wright
btw. this is a great bash cheatsheet https://devhints.io/bash
On 4/17/25 10:21 PM, Mike Wright wrote:
I'm trying to write a bash script. There are 4 arrays: base10 base16 base62 base70.
I want to match an array based on two digits provided by argument $1.
e.g. getArray 70 would select base70
This should show what you need.
#/usr/bin/bash
array1=(1 2 3 4) array2=(5 6 7 8) array3=(9 10 11 12)
declare -n arr=array${1} echo ${arr[$2]}
On 4/17/25 23:23, Samuel Sieb wrote:
declare -n arr=array${1} echo ${arr[$2]}
My hat is off to you, good sir.
I'd bumped into declare earlier today but couldn't grasp it in the context where it was used.
With your help I now have my password generator working.
pwgen [length] [radix]
I use radix=70 when I'm dealing with the uninformed sites that still insist on numbers, upper and lower alpha, and a "special" character.
I guess they never got the memo that a larger character set helps a little but a slightly longer password is exponentially stronger.
Thank you, Mike Wright
On Fri, 2025-04-18 at 00:17 -0700, Mike Wright wrote:
On 4/17/25 23:23, Samuel Sieb wrote:
declare -n arr=array${1} echo ${arr[$2]}
My hat is off to you, good sir.
I'd bumped into declare earlier today but couldn't grasp it in the context where it was used.
With your help I now have my password generator working.
pwgen [length] [radix]
I use radix=70 when I'm dealing with the uninformed sites that still insist on numbers, upper and lower alpha, and a "special" character.
I guess they never got the memo that a larger character set helps a little but a slightly longer password is exponentially stronger.
Not specific to your question, but I highly recommend shellcheck as a way to catch errors and ambiguities in Bash scripts. I've found it to be very helpful.
dnf info shellcheck
poc
On 04/17/2025 11:21 PM, Mike Wright wrote:
btw. this is a great bash cheatsheet https://devhints.io/bash
So is this one: https://tldp.org/LDP/abs/html/