CS 279 - Week 13 Lecture 1 - 11-13-12

a few more words about bash function "effects"
-----------------------------------------------
*   can a bash function return a value? (in a functional sense?)
    *   I'd say -- not exactly, but kind of;

*   how can a bash function "affect" what is around it?
    *   it can change the state of "global" variable or variables 
        (that's a side-effect, note, not a true "return")

    *   it can use the exit command to end the function -- this
        does return an exit status, BUT since this also ends the
	script that CALLED this function, it might be a bit drastic!

        *   funct-exit.sh and call-funct-that-exits.sh demonstrate
            that this is, indeed, the case;

    *   it can use the return command to end the function --
        THIS IS NOT THE SAME AS A C++ return, as it does not return
	a function value, BUT rather it returns an exit status!

        ...but it also DOESN'T end up exiting the calling shell script,
        so that shell script CAN use %? to see the exit status of
	this function once it is completed

        *   think about how a bash function is called -- just like
	    a UNIX command or shell -- where WOULD a "returned" value
	    go, really?

        *   see funct-return.sh and call-funct-that-returns.sh to 
            demo that this is indeed the case;

    *   the function can output to standard out, which can be "caught" 
        by the caller, for example with backquotes!

	result=`funct_called $val blah`

        ...which ironically kind of looks closest to "traditional-ish"
	function return, even though it isn't!

        *   see echo3.sh, which includes the following call to a
            function echo3, catching what it echoes to standard out
	    using backquotes into a variable

	    trio=`echo3 la`

a few more notes about bash functions
--------------------------------------
*   remember: a bash function cannot modify its arguments (how WOULD
    you modify $1? 1=...?)

*   note that a bash function CAN be recursive -- see factorial.sh

a few words on ftp/sftp
------------------------

FTP - File Transfer Protocol - a protocol for transmitting
      files to and from a remote computer

ftp is a program thst uses FTP to transmit files to and
from a remote computer that understands that protocol

(from Wikipedia)
sftp - secure ftp - the sftp program is a command-line
       interface client program implementing the
       client-side of the SSH File Transfer Protocol
       as implemented by the sftp-server command by
       the OpenSSH project,
       which runs INSIDE the encrypted Secure Shell
       connection
        
*   command-line sftp: call with:

    sftp username@host

    sftp st10@nrs-labs.humboldt.edu

         ^^^ if you omit the username, uses the username of the
             current shell -- if that ISN'T the same as the username
	     on the remote machine, you WON'T be able to log in.

*   at the sftp> prompt, you can type various sftp commands -- here are a
    FEW useful ones to get you started:

    ?   - gives a list of sftp commands, each with a 1-line description 

    cd directory_name 
        - change to directory directory_name on the remote machine

    lcd directory_name 
        - change to directory directory_name on your (local) computer 

    pwd - see the name of the current directory on the remote machine

    lpwd 
        - see the name of the current directory on your (local) computer 

    put file_name 
        - transfer a copy of the file file_name from your (local) computer 
          to the remote machine

    get file_name 
        - transfer a copy of the file file_name from the remote machine 
          to your (local) computer 

    quit 
        - exit sftp