Home > Undergraduate > Open Source Tools and Scripting >    Labs

  CITS2003 OPEN SOURCE TOOLS AND SCRIPTING
 
 

Lab 6: Arithmetic and Find

Questions

  1. 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.
    > ./triangle.sh -r 1
    *
    
    > ./triangle.sh
    *
    **
    ***
    ****
    
    > ./triangle.sh -r 6
    *
    **
    ***
    ****
    *****
    ******
    
  2. Modify your triangle script so that instead of printing *s, it prints a character selected using the rules below:
    • If you are printing the last column, print \
    • Otherwise, if you are printing the first column, print |
    • Otherwise, if the row number is odd, print L
    • Otherwise, print *
    > ./triangle.sh -r 1
    \
    
    > ./triangle.sh
    \
    |\
    |L\
    |**\
    
    > ./triangle.sh -r 6
    \
    |\
    |L\
    |**\
    |LLL\
    |****\
    
  3. Find the file called kangaroo.cow. Hint: start in /usr
  4. Fine the directory called mess under /lab
  5. 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.

Bonus

  1. 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

UWA