答案1
两个问题:
echo
在每个输出后添加换行符。尝试echo -n
在 bash 中使用,或者printf
.条件不对。您需要删除内部括号:
if ((i==1 || i==rows || j==1 || j==cols))
答案2
我已经按照下面的方法完成了并且效果很好
命令
for i in {1..6}; do echo "*"; done| paste -s; for i in {1..4}; do echo "* *"| awk '{printf "%s%40s\n",$1,$2}'; done;for i in {1..6};do echo "*";done| paste -s
output
for i in {1..6}; do echo "*"; done| paste -s; for i in {1..4}; do echo "* *"| awk '{printf "%s%40s\n",$1,$2}'; done;for i in {1..6};do echo "*";done| paste -s
* * * * * *
* *
* *
* *
* *
* * * * * *