Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
let's draw diamond (function)
#!/bin/bash # GNU bash, version 4.4.20 print_debug(){ if test -n "$flag_debug"; then printf '%-3s%2s-%-3s|' $iter $left $right fi } draw_diamond(){ (( length = $1 )) flag_debug="$2" for (( iter=1; iter<=length; iter++ )); do (( left = $length - $iter +1 )) (( right = ( $length-$left ) * 2 + 1 )) print_debug printf %"$left"s%"$right"s'\n' '/' '\' done for (( iter=length; iter>=1; iter-- )) do (( left = $length - $iter + 1 )) (( right = ( $length-$left ) * 2 + 1 )) print_debug printf %"$left"s%"$right"s'\n' '\' '/' done } draw_diamond 2 verbose draw_diamond 10 ## RTFM # special thanks to: # printf, test, bash # bash's builtin: # if, for, let, function ##
run
|
edit
|
history
|
help
0
aaa
a shell script to say good morning/afternoon/evening
a
dico.txt
How do I view all available HDD's/partitions?
180420107522
init
escribir_en_la_memoria.sh
heyy
FCFS_done