Pure bash 166
printf -v l %$[$1/2]s
echo " ${l// /____}"
(($1%2))&&r=''||r=' /'
printf -v l %$[(1+$1)/2]s
echo "${l// / /\\ }$r"
printf -v l %$[(1+$1)/2]s
echo ${l// //__\\}${r# }
In action:
triangle() {
printf -v l %$[$1/2]s
echo " ${l// /____}"
(($1%2))&&r=''||r=' /'
printf -v l %$[(1+$1)/2]s
echo "${l// / /\\ }$r"
printf -v l %$[(1+$1)/2]s
echo ${l// //__\\}${r# }
}
then now:
for i in {1..12};do echo $i ;triangle $i;done
1
/\
/__\
2
____
/\ /
/__\/
3
____
/\ /\
/__\/__\
4
________
/\ /\ /
/__\/__\/
5
________
/\ /\ /\
/__\/__\/__\
6
____________
/\ /\ /\ /
/__\/__\/__\/
7
____________
/\ /\ /\ /\
/__\/__\/__\/__\
8
________________
/\ /\ /\ /\ /
/__\/__\/__\/__\/
9
________________
/\ /\ /\ /\ /\
/__\/__\/__\/__\/__\
10
____________________
/\ /\ /\ /\ /\ /
/__\/__\/__\/__\/__\/
11
____________________
/\ /\ /\ /\ /\ /\
/__\/__\/__\/__\/__\/__\
12
________________________
/\ /\ /\ /\ /\ /\ /
/__\/__\/__\/__\/__\/__\/