abstract.sh

A highly abstract function invocation, just enjoy it ,guys!

#!/bin/bash

loop()
{
   for((${1}=0; ${1}<${2}; ++${1})); do
        eval \$\{{3..12}\}
   done
}

numb()
{
   echo -n "${!1}${!2}${!3} "
   (( ${3} == 2 )) && echo
}

eval loop" "{i..k}" 3" numb {i..k} 

And what is it actually for...? Why use it?

Rule of thumb is, if you're using eval, there's generally a better way.

Just for fun!
This style of coding is very Concise and flexible!:smiley:

... and if you don't explain it, we will delete it....

This forum is full of busy people, so explain yourself, please.

I was brave enough to run this, and see that it doesn't do anything malign:

$ ./unknown.sh

000 001 002
010 011 012
020 021 022
100 101 102
110 111 112
120 121 122
200 201 202
210 211 212
220 221 222

$

Though I still don't understand it's purpose.

The most easy way to get the same result is

echo {0..2}{0..2}{0..2} | xargs -n 3

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!:smiley:

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.

Sorry,Neo, just delete this post, it's my fault!

POSIX:

set 0 1 2
for i; do
  for j; do
    for k; do
      printf "%s " "$i$j$k"
    done
    printf "\n"
  done
done

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.