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!                

Summary                

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.                 

Arguments                

ruler will take one optional command-line argument:                 

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

Examples                

Here are some examples, where % is my prompt:

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

Requirements                

    #! /bin/bash

Hints                

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                 

Check: HTML CSS
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