Last active
August 30, 2022 16:18
-
-
Save grepwood/2696d40059c21873e8ee to your computer and use it in GitHub Desktop.
Revisions
-
Michael Dec revised this gist
Jan 27, 2015 . 1 changed file with 7 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,17 +14,15 @@ function fill_middle { done } function internal_draw { printf "$1" fill_middle "$2" echo "$1" } function draw_middle { for((X=2; X < SIDE_LENGTH; X++)); do internal_draw "$SIDE_SIGN" " " done } @@ -44,6 +42,6 @@ elif [ "$SIDE_LENGTH" -eq "1" ]; then exit fi internal_draw "$CORNER_SIGN" "$SIDE_SIGN" draw_middle internal_draw "$CORNER_SIGN" "$SIDE_SIGN" -
Michael Dec created this gist
Jan 27, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ #!/bin/bash function internal_rtfm { echo "Draw squares in bash, with different sides and corners" echo "Usage: $0 x y z" echo " x - size of the square to draw" echo " y - character for sides" echo " z - character for corners" exit } function fill_middle { for((Y=2; Y < SIDE_LENGTH; Y++)); do printf "$1" done } function draw_top { printf "$CORNER_SIGN" fill_middle "$SIDE_SIGN" echo "$CORNER_SIGN" } function draw_middle { for((X=2; X < SIDE_LENGTH; X++)); do printf "$SIDE_SIGN" fill_middle " " echo "$SIDE_SIGN" done } if [ "$#" -lt "3" ]; then internal_rtfm fi SIDE_LENGTH=$1 SIDE_SIGN=$2 CORNER_SIGN=$3 if [ "$SIDE_LENGTH" -le "0" ]; then echo "Side length must be a natural number" internal_rtfm elif [ "$SIDE_LENGTH" -eq "1" ]; then echo $CORNER_SIGN exit fi draw_top draw_middle draw_top