I have this script that prints out a box frame with Asterisk signs, and I need to make it so that the script prints out multiple boxes under each other. How can I do it?
#!/bin/bash
#
echo -n "Please enter the amount of lines: "
read lines
echo -n "Please enter the amount of *: "
read sign
for((i = 1; i <= $lines; i++))
do
echo -n "$i "
if [ $i -eq 1 -o $i -eq $lines ]; then
for((j = 1; j <= $sign; j++))
do
echo -n "* "
done
else
echo -n "* "
for((j = 2; j < $sign; j++))
do
echo -n " "
done
echo -n "* "
fi
echo
done
#end
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If you just want the number of boxes as an input, it is just:
#!/bin/bash
#
echo -n "Please enter the amount of lines: "
read lines
echo -n "Please enter the amount of *: "
read sign
echo -n "Please enter the amount of boxes: "
read boxes
for ((h = 1; h <= $boxes; h++))
do
for((i = 1; i <= $lines; i++))
do
echo -n "$i "
if [ $i -eq 1 -o $i -eq $lines ]; then
for((j = 1; j <= $sign; j++))
do
echo -n "* "
done
else
echo -n "* "
for((j = 2; j < $sign; j++))
do
echo -n " "
done
echo -n "* "
fi
echo
done
done
#end
Not sure whether this is what you want though, because if you wrote your code you should have probably figured it out.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0