I am writing a simple script to create all combinations of a and b of a given length (say 10). I want to be able to do this on the command line (I know this is pretty easy if I just put everything in a bash script file and executed it). However, I was wondering if additional files could be dispensed with. Here is what I still have:
n=10; for i in `seq 1 1 $n`; do echo "for a$i in {a..b}; do "; done; echo -n "echo "; for i in `seq 1 1 $n`; do echo -n '$'"a$i"; done; echo; for i in `seq 1 1 $n`; do echo "done;"; done
(I formatted the code for readability, but actually everything on the same line starts from the prompt)
This gives me the following result:
for a1 in {a..b}; do for a2 in {a..b}; do for a3 in {a..b}; do for a4 in {a..b}; do for a5 in {a..b}; do for a6 in {a..b}; do for a7 in {a..b}; do for a8 in {a..b}; do for a9 in {a..b}; do for a10 in {a..b}; do echo $a1$a2$a3$a4$a5$a6$a7$a8$a9$a10 done; done; done; done; done; done; done; done; done; done;
which is just great. If I copy this and bring it back to the command line, it will work like a charm and give me the result.
The question is, how can I do this only with the initial script, without copying and without redirecting anything to files.
I tried sticking $ () around the script, but this gives me "No command" for the "found", as this is not a real command, but a built-in bash. I tried to put eval somewhere before that, but I just keep getting more errors. I'm a little stuck, so any help would be greatly appreciated.
(By the way, Iβll just repeat, Iβm doing it more or less just to find out more bash - why I donβt want to redirect the output to a file and then execute this file. I know how to execute this part, but I donβt know how it is make from the command line)
source share