but, if we don't perform it this way, instead,generally speaking, we must need three nested-loop to accomplish it
for((i=0; i<3; ++i)); do
for((j=0; j<3; ++j)); do
for((k=0; k<3; ++k)); do
echo -n "${i}${j}${k} "
(( k == 2 )) && echo
done
done
done
My purpose is just to show that there are always better solutions to perform the tasks if only you can use your imagination as much as possible!
The post here is intended to show some core concepts and skills that we can perform in shell scripting!
Feel free to delete it if you consider it's useless, Neo!
I'd argue there's a difference between 'better' and 'compact', especially when talking about efficiency, scalability, and safety... That'd blow up into swapdeath if you tried to generate millions of numbers, or do terrible things if someone put an `rm -Rf ~/` into that eval.
This isn't quite as brief, but manages 5 numbers in 2 loops, and can be turned higher just by tacking as many variables as you want onto that set.
#!/bin/bash
set -- A B C D E
while [ "$X" != "Z" ]
do
[ "$X" = $1 ] && printf "\t"
for X in $*
do
printf "%d" "${!X}"
done
for X in $* Z
do
[ $X = $2 ] && echo
(($X=(++$X % $#))) && break
done
done
My note to you is not to post code without explaining the purpose and what you are trying to do. Others made the same comment; and also the moderators made notes to the same effect.
If you have some "great imaginative idea" or point to make, you need to explain your point and not just post some code fragment without explanation as if playing a game. Your comment:
... provides no explanation of what you are hoping to accomplish.
I much prefer Scrutinizer's version because it doesn't use bash extensions. It easy to follow, and does not contain the dreaded eval command. The version in post #1 is one of the worst and most obscure pieces of code I have ever seen.
Might be an accident but the script appears to generate a sequence 0-222 working in number base 3.