Skip to main content.

Assign 0: UNIX and Bash

Table of Contents:

Goals for Assignment 0

After the assignment, you should

  1. Know how to learn about new commands and use them
  2. Know how to make environment variables and customize your environment.
  3. Know how to use some chmod, file system, and process commands.
  4. Know how to redirect output
  5. Have a better understanding of UNIX permissions
  6. Understand pipes and how to use them effectively
  7. Know how to write basic bash scripts, including using if statements and for loops.


You're going to practice your Unix commands and set up your environment, and then show that you did them in a bash script that you'll execute and save in an output file.

This is due before class on February 4.

Objective: Environment Variables

  1. Create two new environment variables called CS397, which represents the path to the course directory, and HANDOUTS that is the path to the course's handouts directory.
    1. Open ~/.bashrc using emacs or jedit or your favorite text editor

      Recall that hidden files (those that start with .) are not shown by default when you list files in your directory. Use the -a option. In text editors, you may need to figure out how to show hidden files.

    2. At the bottom of the file, create a new variable:
    3. Export the variable: export CS397
    4. In terminal, run the source command to load your new profile
      source ~/.bashrc
    5. Check that your new variable was created by displaying its value.
    6. Use the variable by going to that directory, i.e., cd $CS397
    7. Follow a similar process for the HANDOUTS variable. Note, since you have the variable CS397, you may want to use that in defining your HANDOUTS variable's value.
  2. In a new terminal (so that it loads the updated .bashrc file),
    1. Display the $HANDOUTS variable
    2. Display the basename of $HANDOUTS
    3. Display the directory name of $HANDOUTS

Objective: Learning new Unix commands

Use the man command to learn about the yes and touch command. You'll need to "prove" that you learned these commands later in this assignment.

Objective: Customizing Your Prompt

  1. Open up your .bashrc file in your favorite text editor.
  2. Search for force_color_prompt
  3. Uncomment the line that says fore_color_prompt=yes
  4. Search for the definition of PS1.
  5. Comment out (#) the PS1 definition. (Which branch of the if should you be in?)
  6. Add the following code below the commented out prompt.
    PS1="\e[1;31m\h:\W \u (\!)\$ \e[00m"
  7. Source the .bashrc file. What does this prompt look like?
  8. Run ps and some other commands to better buess what the prompt is doing.
  9. Then try setting it as
    PS1='\e[00;35m\]\! \e[00;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
  10. Try out more by checking out the wiki page on customizing your prompt.
  11. You can revert your prompt to the original, commented out prompt or to whatever you want to use for your prompt.

Objective: Aliases

  1. Open (or create) ~/.bash_aliases file.
  2. Create an alias so that ssh aliases to ssh -XY. Then, whenever you ssh, you'll automatically have the -XY options.
  3. Reload your configuration file by running source ~/.bashrc Test that your new alias works. (I'll be able to see that you did this correctly from the next objective.)
  4. Create an alias called "peptalk" that is aliased to repeatedly print "You can do it!"

Objective: Unix Commands (100 pts)

If you haven't already, create a cs397 directory in your home directory and an assignments subdirectory. Create an assign0 subdirectory within assignments.

In conclusion, you should have the directory $HOME/cs397/assignments/assign0

Do the following steps within ~/cs397/assignments/assign0 directory.

You're going to create a script called in your assign0 directory that demonstrates the following tasks. BUT FIRST, practice them on the command line, then put them into the script, as you go, and make sure the output from the script is what you expect. You will be practicing using both absolute and relative paths in this assignment. Use whichever is easier/simpler (i.e., favor relative paths).