我如何让这个脚本打印出多个框?

我如何让这个脚本打印出多个框?

我有一个脚本可以打印出带有星号符号的框框,我需要制作它以便脚本打印出多个彼此下方的框。我该怎么做?

#!/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

答案1

如果您只想将盒子的数量作为输入,则只需:

#!/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

但不确定这是否是您想要的,因为如果您编写了代码,您可能应该已经弄清楚了。

相关内容