0

So, I'm starting to make some decent progress into my test environment for learning bash. I'm still definitely learning the fundamentals and have google searched for about an hour now.

I'm trying to create variables for basically all parts of this so it's easily changeable - from directories to file path names.

**

My current code:
parent_directory='/home/local/test_scripts'
directory_name='app_ms'
directory_output='1..4'
file_name='test'
file_output='log,out'
file_repeat='1..10'
mkdir -p $parent_directory $parent_location/$directory_name{directory_output};
touch $parent_directory/$parent_location/$directory_name{directory_output}/$file_name{file_output} $file_name{file_output}.{file_repeat}

**

Up until the point of when I unclude the brackets - {file_repeat}, everything works as I anticipate it to.

Ideally, I would like the output to represent:

**mkdir -p /home/local/test_scripts /home/local/test_scripts/app_ms{1..4}
touch /home/local/test_script/app_ms{1..4}/test.{log, out}
touch /home /local/test_script/app_ms{1..4}/test.{log, out}.{1..4}**

TL;DR: Is there something I'm missing when trying to create multiple files within the brackets? When I call a variable inside, it is only creating a single directory named "app_ms{1..4}" when I used the variable call method. If I type it all straight out, it creates app_ms1, app_ms2, app_ms3, and app_ms4 and created all the files that I want inside the folders.

1 Answers1

0

Expansion order doesn't work that way. The result of variable expansion is not brace expanded. So you can get those strings as output but you can't (without eval which you don't want) get the shell to run them that way.

See Shell Expansions for more details and the order they are performed in.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • Ok. I'll take a look at this. I more or less chose this way to learn as in depth as possible. Was hoping to find a solution that would allow me to accomplish this. Thanks! – jdspringr07 Feb 12 '15 at 04:32
  • `eval` will let you do it but `eval` is evil and prone to opening up **gaping** security holes and causing other problems. – Etan Reisner Feb 12 '15 at 04:33