Help arranging text

By using this code how can we get the stars in inverted positions?

str="*"

for i in 1 2 3 4 5
do
   echo "$str"
   str="$str *"
done

The output should be like this

* * * * *
   * * * *
      * * *
         * *
            *

Please note that the expert members on this forum initially only see your thread title so please don't use titles like "Help". Give us all a clue what the problem is that we can see WITHOUT opening your thread. We can't sit here all day opening every thread to see what it's about. Also, don't post in this forum "Contact Admins and Mods" unless you're trying to contact the management team.

Please read the forum "Rules" available on the main menu. Read rule #11

1 Like

It would be beneficial to mention OS and shell version that you use so the solution proposals can be based on facts.

Assuming bash or ksh to be your shell, try

str="* * * * *"
for i in 1 2 3 4 5
  do   echo "$str"
       str="${str/\*/ }"
  done
* * * * *
  * * * *
    * * *
      * *
        *
1 Like

Drawing in text is not quite straight forward without the aid of terminal escape codes but here you go:-

#!/bin/bash
str="* * * * *"
spc="   "
echo "$str"
for i in 2 4 6 8
do
	newstr="$spc${str:$(($i-2)):$((9-$i))}"
	spc=$spc"   "
	echo "$newstr"
done

Results, OSX 10.12.0, default bash terminal.

Last login: Mon Oct 31 14:40:10 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> chmod 755 draw.sh
AMIGA:barrywalker~/Desktop/Code/Shell> ./draw.sh
* * * * *
   * * * *
      * * *
         * *
            *
AMIGA:barrywalker~/Desktop/Code/Shell> 

Thread has been renamed to 'help arranging text', please give your threads more useful titles than 'help' in the future.