This lab consists of two questions.
I have two shell scripts that are “the same” (just you wait), but I created them on different platforms: hello-unix was created on Linux, hello-windows was created on Windows. When I test both on Mathlab, hello-windows has a problem, and it doesn't matter how I run it (by calling sh, by calling bash, as an executable):
$ sh hello-windows hello-windows: 5: Syntax error: end of file unexpected (expecting "then") $ bash hello-windows hello-windows: line 5: syntax error: unexpected end of file $ ./hello-windows -bash: ./hello-windows: /bin/sh^M: bad interpreter: No such file or directory
hello-unix does not have a problem:
$ sh hello-unix hello $ bash hello-unix hello $ ./hello-unix hello
WHYYYYY???!!!
Both files are on Mathlab in /courses/courses/cscb09s25/laialber/l03 so you can (and should) see for yourself.
Some ways to start investigating:
ls -l
to find out.) Why are
they different?
od
for how to print out exact bytes and expose invisible
bytes. Try od -c
for this investigation.
What to hand in: wtf.txt containing your short answer for how Windows and Unix differ in text files. (If you just answer the 3rd bullet point above, that will suffice.)
P.S. Now that you know, you have no excuse for handing in a shell script that breaks on Mathlab!
This is a small exercise in basic shell scripting.
The shell script you will write will be called “check
”. Its
job, in short, is to check existence and/or directory-ness of user-provided
paths. In detail:
For each command line argument p, we treat it as a path, and:
If p exists as a directory, print
p is a directory.
If p exists but is not a directory, print
p exists.
If p does not exist, print
p does not exist.
At the end, print out the number of paths found and the number of paths checked, in this format:
n of m paths found.
Example: sh check /usr/bin/date "I don't exist" /usr/bin
The output should be:
/usr/bin/date exists. I don't exist does not exist. /usr/bin is a directory. 2 of 3 paths found.
The expected output is provided as sample-output.txt. Tell the computer to compare for you so it catches typos humans don't see, e.g.:
sh check /usr/bin/date "I don't exist" /usr/bin > actual.txt diff -u sample-output.txt actual.txt
diff
finds and prints line-by-line differences between two text
files. If there is no difference, it outputs nothing, and the exit code is 0.