3460:428/528 UNIX Systems Programming Spring 2016

Section 801 17846/17847

Monday, Wednesday 6:40 - 7:55 pm Arts & Sciences (CAS) 143

@UACS428S16

Instructor

Dr. Michael L. Collard (Schedule)
collard@uakron.edu

News


Atom Feed link

ls.sh now fixed # Posted: Tuesday, Feb 9

Why it had issues

The issue with ls.sh and ls.txt is now fixed. If you copied it before, I would suggest copying it again. If you have worked on the solution, then rename your current ls.sh for safekeeping:

        
  mv ls.sh myls.sh
      

The issue was the line ending of the screenlog file from command screen -L. I recommend reading over the wiki Newline article. In short, line endings are composed of:

  • LF (Line feed, ‘\n’, 0x0A, 10 in decimal)
  • CR (Carriage return, ‘\r’, 0x0D, 13 in decimal)
  • CR+LF (, ‘\r\n’, 0x0D0A)

On UNIX systems, the default line ending is a single LF, on Windows (DOS) it is CR+LF. It appears that the screen command produces logfiles with a CR+LF (Windows-style). I used the file ls.txt to generate the file ls.sh. I should have seen this because the editor emacs which I used when quickly trying to fix the problem in class told me that ls.sh had DOS newlines.

If you need to determine this, you can use the command file:

        
file ls.txt screenlog.0
      

Which produces the result:

        
ls.txt:      ASCII text
screenlog.0: ASCII text, with CRLF line terminators
      

Also, you can use the octal dump command to view the contents:

        
od -c screenlog.0
      

Note: When you use ‘\n’ in C/C++ I/O (e.g., printf(), std::cout), it maps that character to the line ending on the machine on which you compiled. So Windows programs produces ‘\r\n’, and UNIX programs produce ‘\n’.

Project 1 # Posted: Monday, Feb 8

Procedure for Project 1

I am collecting my /home/collard files from a bunch of old servers. I ran across examples that demonstrate various options of bash/UNIX commands. They are a record of an interactive screen session, with the bash prompt as “% ” and the results of the commands. For example, this example shows the usage and output of a command, and would be in a file called cd.txt:

        
% cd /usr
% ls -1
bin
games
include
lib
local
sbin
share
src
      

The commands that produced the cd.txt is in the file cd.sh:

        
export PS4="% "
cd /usr
ls -1
      

So if you were to type these in (with a prompt of ‘%’) you would get the result close to the file cd.txt.

In many cases the commands had options. However, due to a transformation gone bad, the options to the commands have been erased. For example, what is really left of cd.txt is close to:

        
% cd /usr
% ls
bin
games
include
lib
local
sbin
share
src
      

Notice how the “–1” option is missing from the ls command? For this project you will figure out what the options are, based on the basic command (e.g., ls) and the form of the output. In ~collard/Project1 you will find:

  • cd.txt - Output of running the command
  • cd.sh - List of commands, with options to fill in

The file cd.txt is generated from cd.sh by using the screen command with logging:

        
# start a screen with logging
screen -L
# inside the screen session, execute your script
bash -x cd.sh
# once done, exit the screen session
exit
# view your results 
mv screenlog.0 cd.txt
      

You are to take all the *.sh files from my directory ~collard/Project1 and fix the options to the commands. You will place these with the correct names in your own directory, also called Project1. Keep all filenames the same as I have them.

I have started you out with the cd.sh example, and an ls.sh. More commands will be added as I find them. Some starting due dates:

  • Wed, Feb 10: Create your own directory Project1. This should only be readable by you, and no other students
  • Fri, Feb 12: Get the ls.sh working

OS X and GNU/Linux Tools # Posted: Monday, Feb 1

Installing brew

As mentioned in class, OS X on Macs is BSD-based UNIX. Many of the GNU/Linux tools are not installed, and some of the installed BSD tools are not as full featured on the GNU equivalent.

To provide for these tools, I suggest you install Homebrew, which has the tool brew. Home page is available from the title of this news item.

  • Easy to install
  • Easy to update
  • Does not require root (or sudo) account
  • Installs in /usr/local

Archive

Information