CS155: Introduction to Unix

Spring 2018

HW 4

    Note to the next instructor:

    This assignment tacitly assumes that $COLUMNS is usually in your
    environment.  This is an error on my part.  I assumed that $COLUMNS
    was, by default, exported.  However, it’s not.

    One possible fix is to use a different variable: $WIDTH instead
    of $COLUMNS.  If $WIDTH isn’t set, use 80.

CS155 HW4: Rulers!                


Alas, this assignment concerns neither Prime Minister Justin Trudeau of Canada or Queen Jetsun Pema of Bhutan.                 

It it sometimes useful to be able to quickly count columns in a terminal window. For this assignment, you will write a bash script called ruler which will display a ruler.                 


ruler will take one optional command-line argument:                 

If no arguments are given, use the environment variable COLUMNS to determine the length of the ruler. If COLUMNS is not set, assume eighty columns.
ruler half
If the word “half” is given, display a ruler half as wide (round down) as would be otherwise displayed, if no arguments were given.
ruler n
If a single numeric argument is given, display a ruler that wide.


Here are some examples, where % is my prompt:

% echo $COLUMNS
% ./ruler
         1         2         3         4         5         6         7         8
% ./ruler half
         1         2         3         4
% ./ruler 27
         1         2


    #! /bin/bash


There’s a convenient mechanism to get a default value for a Bash variable. Look for it if you’re interested.                 

How to submit your homework:                

Via web checkin, or:                 

    ~cs155/bin/checkin HW4 ruler

How to receive negative points:                

Turn in someone else’s work.                 

User: Guest                 

Edit History Source

Modified: 2018-02-18T14:44                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building