melrom
December 4th, 2008, 11:12 PM
Hi-
I'm creating a shell script that will be taking in data and I want to create separate variables that contain the name of the data taken in.
for instance, if the data obtained is in a variable called $var1 = "txt", I want to create a new variable named "txt_count" somehow using $var1. I am also wondering if I can later test these variables in an if statement, using the same kind of concept.
Something along the lines of $var1_count.
I can't just use an if statement, as I am dealing with a lot of data that I want to do this for.
For instance, in the vain of filenames, if I had txt, jpg, ogg, cpp, I'd want to create corresponding variables txt_count, jpg_count, ogg_count, and cpp_count [except that I am doing this with over 100 pieces of data]. And then later, I want to be able to say, based on having only this $var1 [which could be equal to txt, jpg, ogg, or cpp], and say does $var1_count exist in an if statement or something along those lines.
I'm not sure if this is possible in bash.
I'm creating a shell script that will be taking in data and I want to create separate variables that contain the name of the data taken in.
for instance, if the data obtained is in a variable called $var1 = "txt", I want to create a new variable named "txt_count" somehow using $var1. I am also wondering if I can later test these variables in an if statement, using the same kind of concept.
Something along the lines of $var1_count.
I can't just use an if statement, as I am dealing with a lot of data that I want to do this for.
For instance, in the vain of filenames, if I had txt, jpg, ogg, cpp, I'd want to create corresponding variables txt_count, jpg_count, ogg_count, and cpp_count [except that I am doing this with over 100 pieces of data]. And then later, I want to be able to say, based on having only this $var1 [which could be equal to txt, jpg, ogg, or cpp], and say does $var1_count exist in an if statement or something along those lines.
I'm not sure if this is possible in bash.