Shell Script — Variables for a range of characters gets executed as group of characters

Hi!

I'm having troubles executing a perl-script using variables for a range of characters (or don't really know what to call it).

My situation is that I'm trying to create a macro that based on a prompt will type/past a string of random characters, based on what the prompt returns.

Image of Prompt Action for clarification of what I am trying to do:

The prompt in itself and the if-statements it needs to work as I want is not really the problem. What I am struggling whit is getting the perl-script to behave well with the KMVARiables I am feeding it based on the prompt/if-statements.

The following perl-script works perfectly in of itself:
perl -e '@c=((0..9),("A".."Z"),("a".."z"),("~","!","@","%","^","&","*","(",")","-","_","+","=","{","}","[","]","|",":",";","<",">","?","/","#"));$p.=$c[rand(scalar @c)] for 1..16; print "$p\n"'

Returning a random string of 16 characters like this:
M6q8lvE(_5y=*Fp2

But when adding variables to the script like this I am having problems:
perl -e '@c=(($ENV{KMVAR_RndNumbers}),($ENV{KMVAR_RndUppercase}),($ENV{KMVAR_RndLowercase}),($ENV{KMVAR_RndSpecial}));$p.=$c[rand(scalar @c)] for 1..$ENV{KMVAR_Number_of_caracters}; print "$p\n"'

Getting this abomination of a string of 16 groups of characters:
“A”..”Z”0..90..9”a”..”z””~”,”!”,”@“,”%”,”^”,”&”,”*”,”(“,”)”,”-“,”_”,”+”,”=“,”{“,”}”,”[“,”]”,”|”,”:”,”;”,”<“,”>”,”?”,”/“,”#”0..9”A”..”Z”0..90..9”~”,”!”,”@“,”%”,”^”,”&”,”*”,”(“,”)”,”-“,”_”,”+”,”=“,”{“,”}”,”[“,”]”,”|”,”:”,”;”,”<“,”>”,”?”,”/“,”#”0..90..9”a”..”z””a”..”z””A”..”Z””A”..”Z”

To clarify: Each of the 16 groups consists of either 0..9, "A".."Z", "a".."z" or "~","!","@","%","^","&","*","(",")","-","_","+","=","{","}","[","]","|",":",";","<",">","?","/","#", instead of returning 16 instances of a character form any of these groups (1, 2, 3, A, B, C, a, b, c, ~, !, @, etc.).

I've searched around here for ways to use KMVARiables within shell scrips but haven't been able to find any information about this specific issue. I have also tried combining the variables into one (see example macros bellow) but haven't been able to get this to work either.

Anyone having any ideas on how to tackle this problem?

RandomString (Combined) Macro (v10.2)

RandomString (Combined).kmmacros (8.2 KB)

Or I kind of stumbled upon a halfway solution here now. If I load each of the characters in the character range into a variable of it's own, like this:

perl -e '@c=(($ENV{KMVAR_RndUNumber_0}..$ENV{KMVAR_RndUNumber_9}),("$ENV{KMVAR_RndUppercase_A}".."$ENV{KMVAR_RndUppercase_Z}"),("$ENV{KMVAR_RndLowercase_a}".."$ENV{KMVAR_RndLowercase_z}"));$p.=$c[rand(scalar @c)] for 1..$ENV{KMVAR_Number_of_caracters}; print "$p\n"'

Then it is read/executed correctly by the script. But as I in my case would then also have to create a separate variable for each of the different special characters (I'd also like to be able to choose into the mix) it would be very cumbersome creating this macro. I also don't understand why the script behaves like described in the post above, so still very much hoping for other suggestions or solutions here!

RandomString (SingleCharacterVariables) Macro (v10.2)

RandomString (SingleCharacterVariables).kmmacros (5.7 KB)

I don’t know why you want to generate a range of characters, but there’s a password generator macro that might be worth looking at if only to give you some ideas for achieving what you want.

Thank you for pointing me in the direction of this Macro.
It has many interesting aspects, and also allot of overlap with my use cases (creating strings for passwords being one of them). And anyways inspiration to be found there. (I have to spend more time to understand it though, as it is quite advanced for where I am in my KM learning curve.)

For my use case I think I'd like to try to continue my approach, and would love any further information on why the KMVARs are interacting with the script in the way I described in my first post. There's something here that gives me a feeling that it might be an issue with order of operations or something like that. It's as if the script is run first and the variables are filled in right before it's being printed, or something like that.

I've also been randomly trying to include more or less of the perl -script in the RndCombined variable, like shown bellow, but have not been able to get the script to run like this:

RandomString (Combined 2) Macro (v10.2)

RandomString (Combined 2).kmmacros (5.5 KB)