At the beginning we need to define some global variables.
and empty our $TMP
–folder.
TMP=i/tmp INPUTFOLDER=p OUTPUTFOLDER=o/free/fr LOGODIR=i/free/logosNIRVANA=/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 following grids:
(3*3)=9,
(3*3)*(3*3)=81,
(3*3)*(3*3)*(3*3)=729.
To choose a grid, we read the numbers from the script’s header section with the following command:
AVAILABLEGRIDS=`grep "AVAILABLE GRID" $0 | \ head -1 | \ cut -d "," -f 2,3,4`
Print all lines containing the pattern AVAILABLE GRID
inside
this script ($0
)
with grep
, take only the first appearance (head -1
)
and cut the fields (separated by a ,
) 2,3,4 with cut -d "," -f 2,3,4
.
For different formats we want different grids, e.g. for a poster in DIN A3
Size a total amount of 729 graphics is too much, because graphics get too small.
Therefore we want our script to know that if the paper size is A3 it should only use
9 and 81, but not 729.
When executing the script we provide it with information about the current
format ./wtf.sh A3
.
FORMAT=`echo FORMAT=$1`if [ $FORMAT = "FORMAT=A1" ]; thenGRIDTYPE=`echo $AVAILABLEGRIDS | \ cut -d "," -f 1,2,3 | \ nawk 'gsub(",", "\n")' | \ sed '/^$/d' | \ rl --count=1`elif [ $FORMAT = "FORMAT=A3" ]; thenGRIDTYPE=`echo $AVAILABLEGRIDS | \ cut -d "," -f 1,2 | \ nawk 'gsub(",", "\n")' | \ sed '/^$/d' | \ rl --count=1` else exit 1; fiFORMAT=$1 echo $GRIDTYPE > $TMP/gridsize.i
To define the grid number we use echo
, cut
, nawk
, sed
and rl
as following:
echo
the variable $AVAILABLEGRIDS
that we previously extracted.
Use cut
to select the needed fields.
Split these fields into lines with n
ewer awk
.
Delete all blank lines using sed
(same as “grep
‘.’ ”).
Now that we have split the fields of our variable into lines we can use randomize-lines
(rl
) to randomly select one.
Additionally we write $GRIDTYPE
into a
file
so we can access it later from our
processing sketches
CANVASSCRIPT=`grep -He .*SUITABLE.*,$GRIDTYPE i/*.sh | \ cut -d ":" -f 1 | \ rl --count=1 | \ cut -d "/" -f 2`