========
CS 279 - Week 1 Lecture 2 - 2022-08-24
========
today we will
========
*   what's an operating system? what's a command shell?
*   a few words about some common UNIX/Linux shell programs
*   what is a shell script?
*   how to start a shell script
*   basic UNIX/Linux command syntax
*   trying to get to our first bash shell script
*   [did not reach] START our discussion of UNIX/Linux filesystem and
                    file-related commands
*   prep for next class

=====
*   the app you download for clicker questions
    is named "pointSolutions" on Android
    (and if you search for TurningPoint the pointSolutions
    app comes up, also)

=====
*   favorite quick'n'sleazy definition of an
    operating system (OS):

    an operating system is the INTERFACE between a
    person (or an application program) and the
    computer hardware

*   you can have a graphical user interface
    front end for an OS --

    you can also have a COMMAND SHELL, at which
    you type desired operating systems commands

    *   you type the command you want at a PROMPT

    *   when you type the enter/return key at the end
        of your command,

        THEN it is interpreted/executed,
	its output (if any) is printed to the screen,
	then when done, it displays the prompt again
	(to show it is ready for the next command)

====
a few words about some UNIX/Linux shells
====
*   there are at least 18 kinds of different UNIX/Linux
    command shell programs/interpeters out there...!

    *   you can choose which you use, by the way
        (more on that later!)

*   Five of the significant shells:
    *   the Bourne shell:           sh
    *   the C shell:                csh
    *   the Korn shell:             ksh
    *   the z shell:                zsh
    *   GNU's "Bourne-again shell": bash

    *   Bourne shell -- sh -- written by Stephen Bourne
        at AT&T -- the original UNIX command line interpreter

        *   intro'd basic features common to all these
	    shells --
	    *   piping
	    *   here documents
	    *   command substitution
	    *   variables
	    *   control structures
	    *   filename wildcarding <-- may also be called
	                                 globbing...?

    *   The C shell, csh, was written by Bill Joy while
        a grad student at UC Berkeley
	*   modeled more (its control structures and
	    expression grammar) on the C language

        *   intro'd some influential features for
	    interactive work:
	    *   the history and editing mechanisms
	    *   aliases
	    *   directory stacks
	    *   tilde notation
	    *   job control
	    *   and more

    *   these two influenced many of the subsequent shells,
        happily many of the strengths of both
	(and of other subsequent shells)
	are brought together in bash

    *   bash:
        IS from GNU
	*   is sh-compatible, incorporates useful features
	    from ksh and csh
	*   intended to conform to the POSIX standard

=====
*   what is a shell script, then?
    *   basically, a text file of
        shell commands or executable statements

    *   how does the OS know which shell to use to run those
        commands?
	...good practice: is for the 1st line of
	   a shell script to include an special indication
	   of WHICH shell interpreter to use to execute
	   that script

    *   course text, 2021 edition, Section 23.3, p. 173:
        *   should start a script with
	    #!
	    followed by the full pathname of the shell
	    interpreter to be used for running that script

             #! is often pronounced/read as "she-bang"

        *   in most Linux systems, the full path (at least
	    virtual) for the bash shell is:
	    /bin/bash

        *   so, you SHOULD start a bash shell with:
#!/bin/bash

*   we need a command or two,
    and maybe some basic command syntax...

=====
Basic UNIX/Linux command syntax
=====
*   starts with the name of the desired command
    separated from its option(s) or command-line arguments
        by one or more blanks
    and options are written as a dash: -
        followed by one or more letters
    (whether the order of these matters depends on the
        command...!)

*   example:
    most UNIX/Linux commands have a manual page you
    can access from the shell --

    man

    amongst its arguments and options is to put
    the name of the command you want to read the man page of

    man man
    ...asks to display the UNIX/Linux manual
       page for the man command

*   There's also an echo command,
    it echoes or prints the values of its command-line argument
    expressions to standard output (by default, the screen)

    *   has a -n option, means do not echo a newline
        character at the end of its output

*   to run a shell script,
    it needs to be executable...

    chmod lets you change the mode, or permissions,
       for a file

    one ham-handed way to do this:
    chmod +x hello

    and now, typing ./ and the script name
    will run this script:

    ./hello