Using bash I am trying to create an echo command with a list of variables. The number of variables can differ on what I am trying to do but I know how many I have as I count them in $ctr1. An example of what it should look like is:
echo "$var1,$var2,$var3"
etc. with the last variable the same number as the counter.
Can someone give me an idea as to what I should be doing, an example would be great. I know it could be done with if statements with a line for the possible number in the counter but that is not practical as there can be from 1 to 50+ variables in a line. I do not know if this should be an array or such like nor how to put this together. Any assistance on this would be a help.
val=; for var in "$@"; do val="${val},${var}"; done; echo "${val},$#", then doing something liketest.sh a b c d ewould output,a,b,c,d,e,5(an extra,yeah, but where the variables are coming from might eliminate this, or change the loop completely).