Writing a bash script that will draw an ASCII box around user input. But, I have run into a problem I have not been able to find the solution for.
Above code is supposed to assign to top and bottom lines.
as well as the second and second to last line which should look like this.
But what I get is
How on earth do I build a line consisting of spaces?
Help me Obi Wan.
You are my only hope
Code:
#!/usr/local/bin/bash
###############################################################################
#
# Title: Box
# Purpose: Parse and draw ASCII box around text
# Written by: Tim.Falardeau@SpreadSpectrum.net
#
##############################################################################
VMAX=10
HR="-"
VR="|"
STRING="$@"
echo "STRING = $STRING"
c=1
while [ $c -le $VMAX ]
do
LINE[$c]=`echo $STRING | cut -d ":" -f $c`
if [ -z "${LINE[$c]}" ]; then
break
fi
echo ${LINE[$c]}
c=$((c + 1))
done
NOL=$(( ${#LINE[@]} - 1 ))
echo "\$NOL = $NOL"
BOXH=$(( $NOL + 3 ))
echo "\$BOXH = $BOXH"
LEN=0
for ((c=1; c<=$NOL; c++))
do
if [ ${#LINE[$c]} -gt $LEN ]; then
LEN=${#LINE[$c]}
echo "\$LEN is now $LEN"
fi
done
BWID=$(( $LEN + 4 ))
echo "\$BWID = $BWID"
PL1=1
PL2=$(( $BOXH - 1 ))
echo "PL1 = $PL1"
echo "PL2 = $PL2"
c=0
while [ $c -le $BOXH ]
do
if [ $c -eq 0 -o $c -eq $BOXH ]; then
x=0
HR="-"
while [ $x -le $BWID ]
do
HR="$HR-"
x=$(( $x + 1 ))
done
OUTSTR[$c]=$HR
elif [ $c -eq $PL1 -o $c -eq $PL2 ]; then
x=0
SP=" "
while [ $x -le $LEN ]
do
set SP="$SP "
x=$(( $x + 1 ))
done
OUTSTR[$c]=$( echo -n "| "$SP" |" )
fi
echo "\${OUTSTR[$c]} = ${OUTSTR[$c]}"
c=$(( $c + 1 ))
done
exit 0
Above code is supposed to assign to top and bottom lines.
as well as the second and second to last line which should look like this.
Code:
-------------------
| |
<LINES WILL GO HERE>
| |
--------------------
But what I get is
Code:
--------------------
| |
<LINES WILL GO HERE>
| |
--------------------
How on earth do I build a line consisting of spaces?
Help me Obi Wan.
You are my only hope
