Thread: drawing a shape with shell script
i'm trying draw tree in following form
as can see need both spaces, , "*" stars in every line, can't quite way wantcode:* *** ***** ******* *********
code:#!/bin/bash display_tree() { local rows=$1 local columns=$2 for ((i=0; i<$rows; i++)) do #spaces loop for ((j=0; j<$columns; j++)) do echo -n " " #drawing tree loop for ((a=0; a<$(($i + 1)); a++)) do echo -n "*" done done echo done } if [ $# -eq 2 ]; display_tree $1 $2 else echo "usage: $0 rows columns" fi
code:$ n=6; row=""; $ for(( i=0; i<n; i++ )); row="$row "; done; row="${row%?}*"; for(( i=0; i<n; i++ )); echo "$row"; row="${row#?}**"; done * *** ***** ******* ********* ***********
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] drawing a shape with shell script
Ubuntu
Comments
Post a Comment