Math-Tuttle-OSX:279lectures smtuttle$ cd 279lect08-2
Math-Tuttle-OSX:279lect08-2 smtuttle$ ls
279lect08-2-q1-braille.doc
279lect08-2-q1-braille.odt
279lect08-2-q2-braille.doc
279lect08-2-q2-braille.odt
279lect08-2-q3-braille.doc
279lect08-2-q3-braille.odt
279lect08-2-q4-braille.doc
279lect08-2-q4-braille.odt
279lect08-2.odt
279lect08-2.pdf
either.sh
either.sh~
greeting.txt
looky
salut.txt
shells1
shells2
simple-read.sh
simple-read.sh~
there
y-or-n.sh
y-or-n.sh~

Math-Tuttle-OSX:279lect08-2 smtuttle$ test -e pig.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
1

Math-Tuttle-OSX:279lect08-2 smtuttle$ echo oink > pig.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ test -e pig.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
0
Math-Tuttle-OSX:279lect08-2 smtuttle$ test -e pig.txt; echo $?
0

Math-Tuttle-OSX:279lect08-2 smtuttle$ simple-read.sh 
please type something followed by enter: moo
you entered: <moo>

Math-Tuttle-OSX:279lect08-2 smtuttle$ simple-read.sh 
please type something followed by enter: moo and oink
you entered: <moo and oink>

Math-Tuttle-OSX:279lect08-2 smtuttle$ simple-read.sh 
please type something followed by enter:    aha   
you entered: <aha>

Math-Tuttle-OSX:279lect08-2 smtuttle$ simple-read.sh 
please type something followed by enter: moo  and  oink
you entered: <moo  and  oink>

Math-Tuttle-OSX:279lect08-2 smtuttle$ chmod 700 loop-read.sh

Math-Tuttle-OSX:279lect08-2 smtuttle$ loop-read.sh
type a blank-separated list followed by enter: 
moo and baa and la la la
<moo>
<and>
<baa>
<and>
<la>
<la>
<la>
and the $input was moo and baa and la la la

Math-Tuttle-OSX:279lect08-2 smtuttle$ either.sh
Enter something: foo
$input: foo

Math-Tuttle-OSX:279lect08-2 smtuttle$ either.sh foo
$input: foo

Math-Tuttle-OSX:279lect08-2 smtuttle$ y-or-n.sh
do you want to play a game? no
final reply: no

Math-Tuttle-OSX:279lect08-2 smtuttle$ y-or-n.sh
do you want to play a game? oh yeah
please enter y for yes or n for no: heck no
please enter y for yes or n for no: NOOOO
final reply: NOOOO

Math-Tuttle-OSX:279lect08-2 smtuttle$ y-or-n.sh
do you want to play a game? y'
final reply: y'

Math-Tuttle-OSX:279lect08-2 smtuttle$ test -f ~/.bash_profile
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
0

Math-Tuttle-OSX:279lect08-2 smtuttle$ ln -s pig.txt softy.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ test -f softy.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
0

Math-Tuttle-OSX:279lect08-2 smtuttle$ ls /dev
afsc_type5	    	        ptywf
auditpipe		        random
auditsessions			rdisk0
... <MANY more lines of device special files chopped> ...

Math-Tuttle-OSX:279lect08-2 smtuttle$ !ssh
ssh st10@nrs-labs.humboldt.edu
st10@nrs-labs.humboldt.edu's password: 
Last login: Thu Oct 11 11:45:14 2012 from 137.150.7.22
-bash: /usr/local/bin/oraenv: No such file or directory

[st10@nrs-labs ~]$ ls /dev
autofs              pts     sg25      tty42
block               ram0    sg26      tty43
bsg                 ram1    sg27      tty44
... <MANY more lines of device special files chopped> ...

[st10@nrs-labs ~]$ tty
/dev/pts/4

[st10@nrs-labs ~]$ ls -l /dev | more
total 0
crw-rw----  1 root root     10,  56 Sep 16 10:18 autofs
drwxr-xr-x  2 root root        1140 Sep 16 11:52 block
drwxr-xr-x  2 root root        1000 Sep 16 11:52 bsg
drwxr-xr-x  3 root root          60 Sep 16 03:18 bus
drwxr-xr-x  2 root root         100 Sep 16 03:18 cciss
drwxr-xr-x  2 root root        4860 Sep 16 11:52 char
crw-------  1 root root      5,   1 Sep 16 10:18 console
lrwxrwxrwx  1 root root          11 Sep 16 03:18 core ->
 /proc/kcore
drwxr-xr-x 10 root root         220 Sep 16 10:18 cpu
crw-rw----  1 root root     10,  61 Sep 16 10:18 cpu_dma
_latency
crw-rw----  1 root root     10,  62 Sep 16 10:18 crash
drwxr-xr-x  5 root root         100 Sep 16 03:18 disk
brw-rw----  1 root disk    253,   0 Sep 16 11:52 dm-0
brw-rw----  1 root disk    253,   1 Sep 19 18:49 dm-1
brw-rw----  1 root disk    253,   2 Sep 19 18:49 dm-2
brw-rw----  1 root disk    253,   3 Sep 16 10:18 dm-3
brw-rw----  1 root disk    253,   4 Sep 16 10:18 dm-4
brw-rw----  1 root disk    253,   5 Sep 16 10:18 dm-5
brw-rw----  1 root disk    253,   6 Sep 16 10:18 dm-6
brw-rw----  1 root disk    253,   7 Sep 16 10:18 dm-7
... <MANY more lines of device special files chopped> ...
srw-rw-rw-  1 root root           0 Sep 16 10:18 log
... <MANY more lines of device special files chopped> ...

[st10@nrs-labs ~]$ exit
logout

Connection to nrs-labs.humboldt.edu closed.

Math-Tuttle-OSX:279lect08-2 smtuttle$ tty
/dev/ttys002

Math-Tuttle-OSX:279lect08-2 smtuttle$ which ls vi emacs
/bin/ls
/usr/bin/vi
/usr/bin/emacs

Math-Tuttle-OSX:279lect08-2 smtuttle$ which prepSource3
/Users/smtuttle/bin/prepSource3

Math-Tuttle-OSX:279lect08-2 smtuttle$ which bibbity
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
1

Math-Tuttle-OSX:279lect08-2 smtuttle$ echo oink > pig.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo oink > piggy.txt

Math-Tuttle-OSX:279lect08-2 smtuttle$ cmp pig.txt oink.txt
cmp: oink.txt: No such file or directory
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
2

Math-Tuttle-OSX:279lect08-2 smtuttle$ cmp pig.txt piggy.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
0

Math-Tuttle-OSX:279lect08-2 smtuttle$ echo oink >> piggy.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
0

Math-Tuttle-OSX:279lect08-2 smtuttle$ cmp pig.txt piggy.txt
cmp: EOF on pig.txt
Math-Tuttle-OSX:279lect08-2 smtuttle$ echo $?
1
Math-Tuttle-OSX:279lect08-2 smtuttle$ diff pig.txt piggy.txt
1a2
> oink

Math-Tuttle-OSX:279lect08-2 smtuttle$ ls
#279lect08-2-projected.txt# greeting.txt
279lect08-2-projected.txt   looky
279lect08-2-projected.txt~  loop-read.sh
279lect08-2-q1-braille.doc  loop-read.sh~
279lect08-2-q1-braille.odt  pig.txt
279lect08-2-q2-braille.doc  piggy.txt
279lect08-2-q2-braille.odt  salut.txt
279lect08-2-q3-braille.doc  shells1
279lect08-2-q3-braille.odt  shells2
279lect08-2-q4-braille.doc  simple-read.sh
279lect08-2-q4-braille.odt  simple-read.sh~
279lect08-2.odt		    softy.txt
279lect08-2.pdf		    there
either.sh		    y-or-n.sh
either.sh~		    y-or-n.sh~

Math-Tuttle-OSX:279lect08-2 smtuttle$ diff loop-read.sh*
5,6c5
< read input
< for item in $input
---
> for item in `read input`

Math-Tuttle-OSX:279lect08-2 smtuttle$ diff 279lect08-2-projected.txt simple-read.sh
0a1
> #!/bin/bash
2,3c3,6
< *   aside: how you can get the exit status from
<     a command
---
> # simple example of using the read command to obtain
> #     interactive input from the user
> # by: Sharon Tuttle
> # last modified: 10-10-12
5,91c8
<     *   the variable $? reads the exit status of
<         the last command executed
< 
<     *   after a function returns, $? gives the exit
<         status of the last command executed in the
< 	  function
< 
<     *   following execution of a pipe, it gives
<         exit status of the last command executed
< 
<     *   after a script terminates, a $? from the
<         command-line gives the exit status of
< 	  the script, which is the exit status of
< 	  the last command executed in that script
< 	  (oughta be 0 for success!)
< 
< *   bash shell programming feature of the day:
<     interactive input
< 
<     *   one easy way to get input from a user
<         while a script is running is with
< 	  the read command
< 
<     *   simplest form:
< 
<	read desiredVariable
< 
<	...and the script pauses until the
< 	user enters something,
< 	and what they entered (that string)
< 	becomes the value of desiredVariable
< 
<     *   simple example in simple-read.sh
< 
<         and also several others HERE PLEASE add names!
< 
< some more FILES tidbits (and operations on files)
< *   first: a FEW words on the special files' category
<     of device files...
< 
< *   a device file is associated with each device
<     and provides a useful ABSTRACTION for users ---
<     users "write" to a device by writing to its
<         device file,
<     users "read" from a device by reading from its
<         device file,
<     (and device driver software actually handles the
<     really-more-complex actions of this reading and
<     writing)
< 
< *  conventionally, device files live in the /dev directory
< 
< *   /dev/tty is a special device file typically associated
<     with your terminal;
<     ... there is also a specific designation, which you can find 
<         with the tty command;
< 
< *   /dev/null
<     the null device
<     a "bit bucket"
<     ...anything sent to it, is THROWN AWAY
<     ...when you try to read from it, you get an end-of-file
< 
< *   some interesting file commands...
< 
< which
< -----
< *   followed by one or more commands,
<     outputs the full pathname for that command that
<     it finds by traversing your PATH
< 
< cmp and diff
< ------------
< cmp - does a quick comparison of 2 files
<       if the same? exit status of 0
<       if different? exit status of 1 (and you 
<           might get a message)
<       if one or both can't be accessed? you get
<          exit status of 2
< 
< *   can use its -s option to run "silently"
<     (no outout to standard out, JUST the 
<     exit status)
< 
< diff - analyzes the differences between two files,
<        and gives you a list of transformations for
<        transforming file1 to file2
---
> # note the use of the -n option with echo, so it doesn't echo a newline
92a10,11
> echo -n "please type something followed by enter: "
> read userInput
93a13
> echo "you entered: <$userInput>"

Math-Tuttle-OSX:279lect08-2 smtuttle$ ls shells1
either.sh		    moo.sh    	 simple-read.sh	y-or-n.sh

Math-Tuttle-OSX:279lect08-2 smtuttle$ ls shells2
either.sh		    oink.sh   	 simple-read.sh	y-or-n.sh

Math-Tuttle-OSX:279lect08-2 smtuttle$ diff shells1 shells2
Only in shells1: moo.sh
Only in shells2: oink.sh

Math-Tuttle-OSX:279lect08-2 smtuttle$ mkdir shells1/dir1
Math-Tuttle-OSX:279lect08-2 smtuttle$ mkdir shells2/dir1

Math-Tuttle-OSX:279lect08-2 smtuttle$ echo moo > shells1/dir1/moo
Math-Tuttle-OSX:279lect08-2 smtuttle$ diff -r shells1 shells2
Only in shells1/dir1: moo
Only in shells1: moo.sh
Only in shells2: oink.sh

Math-Tuttle-OSX:279lect08-2 smtuttle$ diff shells1 shells2
Common subdirectories: shells1/dir1 and shells2/dir1
Only in shells1: moo.sh
Only in shells2: oink.sh
Math-Tuttle-OSX:279lect08-2 smtuttle$