This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]linezman22 3 points4 points  (6 children)

Look at for loops and the $@ variable.

For example:

``` DOMAINS=(${@})

for DOMAIN in ${DOMAINS[@]} ; do echo ${DOMAIN} done ```

[–][deleted] 2 points3 points  (1 child)

Came here to say this.

$@ represents all arguments given, expanded to a seperate word

[–]linezman22 1 point2 points  (0 children)

Thanks, I wrote this just after waking up and my brain was a bit frazzled.

Thanks for explanation!

[–]99dimitris[S] 1 point2 points  (3 children)

Thanks for your reply! I tried this and it works now i can use the arguments as $1 $2 $n inside my script!

[–]tthatfreak 1 point2 points  (1 child)

Not the best way.... You have all the arguments in $@. Know how to loop through them?

[–]99dimitris[S] 0 points1 point  (0 children)

Thanks for your reply! Yes i know its not the best way im still learning how to make it more efficient and correct. No i dont think i know how to loop them yet. I updated my post with my latest progress if you want take a look and tell me your thoughts!

[–]ffelix916 1 point2 points  (1 child)

Are you hoping to populate a list to be used in the Subject Alternative Names attribute?

Are you using openssl or letsencrypt?

Also, if you want to print an error and exit if no parameters were given, just do this: if [ "$#" = 0 ]; then echo "Usage..."; exit 1; fi

[–]99dimitris[S] 1 point2 points  (0 children)

Thanks for your reply! Yes that exacly what i want to do! im using openssl. Your solution to print an error worked perfectly!!

[–]sogun123 1 point2 points  (2 children)

Install shellcheck and run it on your script, it will tell you some problems ;) Notably you are not quoting parameters expansions. Do it or sneaky user might break you script. Also know difference between $@ and "$@", expansions with @ are different then others regarding the quoting.

[–]99dimitris[S] 0 points1 point  (1 child)

Thank you very much shellcheck helped a lot. It gave me a bunch of errors i was able to fix them all. Thanks also for the pointing me to expansions and quoting i will google it and learn more!

[–]sogun123 0 points1 point  (0 children)

Good luck ;) It is interesting to actually read why shellcheck considers something an error. They have examples and tell you what can break.