Hello i am trying to create a shell script in bash that will print a box with a height and width given by the user. so far my code looks like this
#!/bin/bash
read height
read width
if [ $height -le 2 ];then
echo "error"
fi
if [ $width -le 2 ];then
echo "error"
fi
#this is where i need help
if [ $height -gt 1];then
if [ $width -gt 1];then
echo "+"
counter=$width
until [ $counter == 0 ]
do
echo "-"
let counter-=1
done
fi
fi
Currently it will print each "-" on a new line, how do i print them on the same line? Thank you
printf "%s" "+"etc to print without a newline. Or optionally omit the format string since you're only printing a single character. You'll also need to use loops properly. It could befor ((i = 0; i < height; i++); do for ((j = 0; j < width; j++)); do ...; done; printf '\n'; doneprintfto generate spaces. It is harder to make it produce a different fill character.