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.
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:
COLUMNSto determine the length of the ruler. If
COLUMNSis not set, assume eighty columns.
half” is given, display a ruler half as wide (round down) as would be otherwise displayed, if no arguments were given.
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
bonehead”, it would be wrong for the program to complain about that argument, and then go on to display a ruler.
bashscript, and not use any other languages such as
awk. You may use programs such as
There’s a convenient mechanism to get a default value for a Bash variable. Look for it if you’re interested.
Via web checkin, or:
~cs155/bin/checkin HW4 ruler
Turn in someone else’s work.