THE UNIVERSITY OF BRITISH COLUMBIA
 
Physics 210 Assignment # 2:
 
EDITORS, BASH & HTML
 
Tue. 14 Sep. 2010 - finish by Tue. 21 Sep.

Every workstation in Henn 205 has all the same accounts as the server hyper.phas.ubc.ca, to which you can log in remotely using ssh (which see). In the following, "hyper" denotes any of these computers; "~" (tilde) refers to your hyper home directory (same as the environment variable $HOME), and all file and directory references are relative to that home directory. You will also be copying files owned by user ~phys210 (the course's home directory on hyper). Be sure to read and follow all instructions carefully, as your grade will depend on certain files being in the right places with the right names. Remember, case matters!

For the tasks below you will need a plain text editor. A few choices are vi, pico, nano, gedit, kedit, nedit, xedit, emacs or xemacs; pick one you like. There are others, but they all have the common feature that they display the raw ASCII characters in a file as you type in or delete or move or modify same. DO NOT try to use a wysiwyg ("what you see is what you get") application like M$-Word or any of the other "word processors" and "Web page editors". I want you to understand HTML (for example) as a simple typesetting language with a straightforward (if primitive) syntax. The wysiwyg applications insert lots of proprietary, encrypted or nonessential garbage; we will know if you use one, so don't!

As always, ask or e-mail me and/or the TAs right away if you encounter problems or don't understand something.

  1. SURVEY: Login to your account on the P210 Website and click on "Survey" in the right column. You will be presented with an admittedly bewildering array of questions about what you know at the start of PHYS 210. Don't worry, we don't expect many experts! Just be careful to note that a "0" answer means, "I have no experience with this," as opposed to "evaluative scores" of 1 through 9, so don't enter "0" if you want to say, "I hate it!" We anticipate that almost no one will have ever heard of some of the Applications, so don't fret if you haven't. This survey will be given again later, to see if we have had any effect on your computing skills.

  2. .bashrc   Your default shell should be bash, the "Bourne Again SHell". There are other shells, like tcsh, that serve roughly the same purpose: to interpret command lines (or files full of command lines) and tell your computer what you want it to do. It starts automatically whenever you open a Terminal window, whose purpose is to give you a place to enter command lines.1 When you open a Terminal window you should be "in bash". If for some reason you find yourself in another shell, you can invoke bash (e.g. from tcsh) as you might expect: with the command "bash". Your shell is a program that "runs" just like any other program; it interprets your keyboard entries until you exit (with the "exit" command), at which point it returns the responsibility for interpreting keyboard entries to the shell from which it was invoked - or, if it was invoked automatically, it will close the Terminal window.

    When bash starts up in your Terminal window, the first thing it does is read the instructions and commands stored in its own special resource (rc) file, .bashrc, that lives in your $HOME directory. If you have no ~/.bashrc file, bash will use the system's default /etc/bashrc file, but, as Billy Holiday said, "God bless the child who's got his own!" So let's.

    I have provided an example .bashrc file in the ~phys210/ directory. First rename ("mv") any existing .bashrc file to .bashrc-old (or whatever makes it easy to remember, in case you decide not to use mine) and then copy ("cp") the example to your own $HOME directory. Edit .bashrc to suit your taste, using "source ~/.bashrc" to reload the file and check the effects of your editing.

  3. .aliases   You can define an alias any time in bash with the command
    "alias <newcommand>='<whatever you want newcommand to do>'"
    but most aliases are usually defined in .bashrc, since this is done for you automatically every time you invoke bash in interactive mode. To keep .bashrc from getting too long and cluttered, it is recommended to separate out the aliases into a file of their own, called .aliases, which is sourced (read in) by .bashrc as follows:2

    if [ -f ~/.aliases ]; then
    source ~/.aliases
    fi

    There are a few simple examples in the sample .aliases file provided in the ~phys210/ directory. These are either self-explanatory or easily decrypted, but they lead the way to greater convenience and power. The examples shown are typical in that their purpose is either to safeguard against careless boo-boos (like "rm *") or to provide a more mnemonic alternative to weird shell command names (like "ls") or to "bundle" a lot of frequently used "switches" (the letters following minus signs in a shell command) into one easily remembered personalized command. Basically, if you find you are always doing something the same way and you get tired of typing in the same details over and over, alias can be a big time-saver.

    The last example in ~phys210/.aliases combines several commands into one, using a semicolon (";") to string them together. You can also combine commands using "&&" or "||", with slightly different effects. Try "man bash" to learn more about the syntax of such combinations. Or, better yet, go to one of the friendlier bash manuals on the Web. Several are listed on our Website (see Manuals and References).

    Finally, in your new .aliases file, add a few aliases of your own to "customize your shell" and make it more comfortable.3

    When you have your .bashrc and .aliases files the way you want them, carefully enter the following commands:

    mkdir /phys210/<you>/a02
    ln -s ~/.bashrc /phys210/<you>/a02/
    ln -s ~/.aliases /phys210/<you>/a02/
    chmod -R o-r /phys210/<you>
    chmod -R g+r /phys210/<you>

    where "<you>" is your account name on hyper.   What does each of these commands do?   Write your explanations in the file   /phys210/<you>/a02/readme.txt   (Hint: the chmod commands4 render the directory tree starting with /phys210/<you> inaccessible to others.5

    NOTE: Unless we get it fixed by Thursday, the above commands will only work if you are logged in to hyper; for some reason they do not work from the workstations in Henn 205 yet. This is not difficult: just use the command

    ssh -Y hyper.phas.ubc.ca

    and answer any questions in the affirmative; you will be asked for your password -- it is the same as on your workstation. When you are there, your command prompt will include the host name "hyper". Then you should be able to execute the commands above. If it still fails, please let us know and we will summon the sysadmin! (There have been mysterious problems....)

  4. EDIT THE wiki: Now that you have registered yourself on the PHYS 210 wiki, responded to the Email confirmation message and been approved by the Administrator, it is time to practice editing this "cooperative document" - first add your brief comment to the bottom of the page entitled, "PHYS 210 ASSIGNMENT 2 (2010): wiki Editing" (don't forget to end your entry with "~~~~" to ensure that you get credit for it!) and then go see if you have anything to add to the "PHYS 210 CORE COMPETENCIES" page. You are not required (or even encouraged) to change the latter page unless you feel an urge to do so, but you should read it and think about it.

  5. YOUR OWN PHYS 210 HOMEPAGE: Create a subdirectory public_html in your $HOME directory on hyper where you can "publish" Web pages. It must be world-readable and -executable.6 The Department's web server will serve up a file in that directory (e.g. ~jess/public_html/filename.html) as a Web address7   http://www.physics.ubc.ca/~jess/filename.html   to any Web browser. I'll refer to ~/public_html as your Web directory. By default, a visitor to the directory http://www.physics.ubc.ca/~jess (with no filename.html) will be shown the contents of a file index.html (if it exists). To prevent others from browsing all the files in your Web directory, you'll want to create index.html there, even if it's empty. (To create an empty file, use "touch index.html".)

    Feel free to use your Web directory for any purpose that does not violate UBC's guidelines for computer use (or waste the Department's resources and bandwidth frivolously). However, we need to reserve a subdirectory for material related to this course. For that purpose you need to "mkdir ~/public_html/p210" to create a subdirectory p210 where we'll know to look for your work.

    In that subdirectory, create a non-empty file index.html that displays your name, address, phone number etc. If you are unfamiliar with HTML syntax, don't worry; plain text with a few formatting commands like <br> ("break") for a new line and <p> for a paragraph will get you by. There are several simple manuals on our course Website if you get stuck. You won't be marked on the elegance or complexity of your new Web page, just on getting it set up and filled with the information specified in the template file at   http://musr.physics.ubc.ca/p210/templates/index.html   which you can copy into your own directory using the "wget" command (a very handy command indeed).8

    Use the plain text editor of your choice to make the specified (in the template) changes to the template index.html file. Add a few suitably labelled links to other Web pages that relate to your favourite topic in Physics or Astronomy. Feel free to add other information if you wish.

    Next, log in to our course Website and Update your Profile so that your Work Web Page points to your own new Homepage. Check your work by verifying that you can get to your Homepage by going to our Course Homepage, selecting "Student Pages" and then your name.



Jess H. Brewer 2010-09-13