Keep a log in the file
lab3.txt of what you do in the
lab so that you can reproduce the results later. This should not
merely be a transcript of what you typed: it should be more like a
true lab notebook, in which you briefly note down what you did and
You're helping to build an application containing a shell script
that invokes the
command to get file status.
Your application is running atop the Maroon Chapeau Enterprise Linux 8 distribution, which uses the
ls implementation supplied by Coreutils 8.29.
running into the problem that some users create a shell
la with the following contents:
#!/bin/sh exec ls -a "$@"
For these users the command
la -A is therefore
ls -a -A. Unfortunately, with
-a option always overrides
-A option regardless of which option is given first,
-A option has no effect in
example, if the current directory has two files
bar, the command
-A outputs four lines, one each
bar. These users want
la -A to output
just two lines instead, one for
.foo and one
bar. That is, for
ls they want a
-A option to override any earlier
option, and vice versa.
You've been asked to look into the problem and fix it. Start by
verifying that the problem still occurs in
the SEASnet GNU/Linux servers. Also, check the Coreutils version
/usr/bin/ls corresponds to.
You discover that the problem is a known bug with Coreutils, Bug#30963. The bug report has a patch intended for publication in a later Coreutils release; see its Message #10. You don't want to wait for the later release to be installed on your system, so you decide to build a copy of Coreutils 8.29 with just this patch added, as follows:
makeat the top level of your source tree, so that you build the fixed version, without installing it into your temporary directory. For each command that gets executed, explain why it needed to be executed (or say that it wasn't neeeded).
lsworks on the same tests where the unmodified
Q1. Does the patch improve the performance of
or make it worse? Briefly explain.
Q2. If your company adopts this patched version of Coreutils instead of the default one, what else should you watch out for? Might this new version of Coreutils introduce other problems with your application?
Consider the Python script
Q3. What happens when this script is invoked on an empty file like
/dev/null, and why?
Q4. What happens when this script is invoked with Python 3 rather
than Python 2, and why? (You can run Python 3 on the SEASnet hosts by
using the command
Write a new script
shuf.py in the style
randline.py; your script should implement the GNU
command that is part of GNU Coreutils.
You should already have a copy of the
source code and documentation; look at the files you created in the
laboratory. However, GNU
shuf is written in C, whereas
you want a Python implementation so that you can more easily add
new features to it.
Your program should support the following
options, with the same behavior as GNU
As with GNU
is used without
your program should run forever.
Your program should also support
zero non-option arguments or
a single non-option argument "
(either of which means read from standard input),
or a single non-option argument other than "
(which specifies the input file name).
Your program need not support the other options of GNU
As with GNU
shuf, your program
should report an error if given invalid arguments.
shuf.py program should not import any
modules other than
string and the modules that
Don't forget to change its usage message to
accurately describe the modified behavior.
shuf.py implementation to Python 3. If you
have trouble with
optparse under Python 3, you can use
argparse module instead. Make sure that
shuf.py still works with Python 2. Don't rewrite
it from scratch; make as few changes as is reasonable.
Submit the following files.
lab3.txtas described in the lab.
hw3.txtcontaining the answer to questions Q1 through Q4 noted above.
shuf.pyas described in the homework.
All files should be ASCII text files, with no carriage returns, and with no more than 80 columns per line. The shell command:
expand lab3.txt hw3.txt | awk '/\r/ || 80 < length'
should output nothing.