At the begin­ning we need to define some global vari­ables. and empty our $TMP–folder.

TMP=i/tmp
INPUTFOLDER=p
OUTPUTFOLDER=o/free/fr
LOGODIR=i/free/logos
 
NIRVANA=/dev/null OUTPUTGLOBAL=o/ ISRANDOM='GENERATES RANDOM OUTPUT' PDFMETA=$TMP/metadata.txt
 
# CLEAR TEMP FOLDER rm $TMP/*

Then we can define some basic parametres.

##############################
# SELECT GRID                #
# AVAILABLE GRIDS:,9,81,729, #
##############################

For the wtf poster we have the fol­low­ing grids:
(3*3)=9,
(3*3)*(3*3)=81,
(3*3)*(3*3)*(3*3)=729.

To choose a grid, we read the num­bers from the script’s header sec­tion with the fol­low­ing command:

AVAILABLEGRIDS=`grep "AVAILABLE GRID" $0 | \
                head -1 | \
                cut -d "," -f 2,3,4`

Print all lines con­tain­ing the pat­tern AVAILABLE GRID inside this script ($0) with grep, take only the first appear­ance (head -1) and cut the fields (sep­a­rated by a ,) 2,3,4 with cut -d "," -f 2,3,4.

For dif­fer­ent for­mats we want dif­fer­ent grids, e.g. for a poster in DIN A3 Size a total amount of 729 graph­ics is too much, because graph­ics get too small. There­fore we want our script to know that if the paper size is A3 it should only use 9 and 81, but not 729. When exe­cut­ing the script we pro­vide it with infor­ma­tion about the cur­rent for­mat ./wtf.sh A3.

FORMAT=`echo FORMAT=$1`
 
if [ $FORMAT = "FORMAT=A1" ]; then
 
GRIDTYPE=`echo $AVAILABLEGRIDS | \ cut -d "," -f 1,2,3 | \ nawk 'gsub(",", "\n")' | \ sed '/^$/d' | \ rl --count=1`
 
elif [ $FORMAT = "FORMAT=A3" ]; then
 
GRIDTYPE=`echo $AVAILABLEGRIDS | \ cut -d "," -f 1,2 | \ nawk 'gsub(",", "\n")' | \ sed '/^$/d' | \ rl --count=1` else exit 1; fi
 
FORMAT=$1 echo $GRIDTYPE > $TMP/gridsize.i

To define the grid num­ber we use echo, cut, nawk, sed and rl as fol­low­ing:
echo the vari­able $AVAILABLEGRIDS that we pre­vi­ously extracted. Use cut to select the needed fields. Split these fields into lines with newer awk. Delete all blank lines using sed (same as “grep ‘.’ ”). Now that we have split the fields of our vari­able into lines we can use randomize-lines (rl) to ran­domly select one.

Addi­tion­ally we write $GRIDTYPE into a file so we can access it later from our pro­cess­ing sketches

CANVASSCRIPT=`grep -He .*SUITABLE.*,$GRIDTYPE i/*.sh  | \
              cut -d ":" -f 1  | \
              rl --count=1 | \
              cut -d "/" -f 2`