Write a script which prints a triangle of * characters. The first row should be a single *, the second **, and so on. You can use echo -n to print output without a newline at the end.
The number of rows is specified by the command line argument -r. If no argument is provided, print 4 rows.
#!/bin/bash
if [[ $# -gt 1 && $1 -eq '-r' ]]
then
size=$2
else
size=4
fi
row=1
while [[ $row -le $size ]]
do
col=1
while [[ $col -le $row ]]
do
if [[ $col -eq $row ]]
then
echo -n '\'
elif [[ $col -eq 1 ]]
then
echo -n '|'
elif [[ $((row%2)) -eq 0 ]]
then
echo -n 'L'
else
echo -n '*'
fi
col=$((col+1))
done
echo
row=$((row+1))
done
Find the file called kangaroo.cow. Hint: start in /usr
find /usr -name kangaroo.cow
Fine the directory called mess under /lab
find /lab -name mess -type d
Scattered across the subdirectories of mess are 5 scripts with the word lab
in their name.
Write a find command to make these scripts executable and move them to
/lab/week6/safe. Remember that wildcards in find patterns
must be quoted, otherwise shell will expand them.
Modify triangle.sh to support command-line arguments for additional functionality:
--bottom -b Print a line of dashes (-) beneath the triangle to form a bottom edge
--rows, -r=ROWS Number of rows to print (default 4)
--character, -c=CHAR Use CHAR in place of * when printing. You may assume CHAR is a single-character string
--help, -h Display this help message and exit
Department of Computer Science & Software Engineering
The University of Western Australia
Last modified: 8 February 2022
Modified By: Daniel Smith