Generating changes with bash

Look for a more suitable solution for the following code:

for i in abc do for j in ABC do for k in 1 2 3 do echo "$i$j$k" done done done 

Of course, there is a simpler solution.

+6
source share
2 answers

It's a little easier

 echo {a,b,c}{A,B,C}{1,2,3} 

or if you want one per line, then

 echo {a,b,c}{A,B,C}{1,2,3} | xargs -n1 

BTW, you can use the extender extension listed above, for example, saving the keyboard, for example, when you need to make backup files, for example:

 cp /some/long/path/And_very-ugly-fileName{,.copy} 

will do /some/long/path/And_very-ugly-fileName.copy without entering a second file name.

+12
source

Use the bracket extension :

 echo {a,b,c}{A,B,C}{1,2,3} 

This will print all possible combinations between the sets {a,b,c} , {a,b,c} and {1,2,3} .

Or even simpler using ranges:

 echo {a..c}{A..C}{1..3} 

And if you want to print each combination in a line, use for -loop:

 for i in {a..c}{A..C}{1..3}; do echo $i; done 
+6
source

Source: https://habr.com/ru/post/926061/


All Articles