UNIX shell environments CS 2204 Class meeting 6
- Slides: 18
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the (C) Doug. Tech. Bowman, Virginia Tech, CS faculty at Virginia Copyright 2001 -2003. 2001
Shell characteristics n n n Command line interface between the user and the system Is simply a program that automatically starts when you login Waits for user to type in commands (C) Doug Bowman, Virginia Tech, 2001 2
Main shell features n Interactivity n n n aliases file-name completion Scripting language n n n Allows programming (shell scripting) within the shell environment Uses variables, loops, conditionals, etc. Next lecture (C) Doug Bowman, Virginia Tech, 2001 3
Various UNIX shells n n n n sh (Bourne shell, original UNIX shell) ksh (Korn shell) csh (C shell, developed at Berkeley) tcsh bash (Bourne again SHell) … Differences mostly in level of interactivity support and scripting details (C) Doug Bowman, Virginia Tech, 2001 4
The Bourne again SHell (bash) n n n We will be using bash and ksh as the standard shells for this class This will be important for shell scripting assignments Superset of the Bourne shell (sh) Borrows features from sh, csh, tcsh & ksh Created by Free Software Foundation (C) Doug Bowman, Virginia Tech, 2001 5
Changing your shell n On most UNIX machines (and lab): n n n which bash (note path) chsh On the some machines: n n which ksh (note path /bin/bash) ypchsh (C) Doug Bowman, Virginia Tech, 2001 6
Environment variables n n A set of variables the shell uses for certain operations Variables have a name and a value Current list can be displayed with the env command A particular variable’s value can be displayed with echo $<var_name> (C) Doug Bowman, Virginia Tech, 2001 7
Some Environment variables Some interesting variables: HOME, PATH, PS 1, USER, HOSTNAME, PWD $HOME /home/gradstudents/m/miali $PATH /usr/local/bin: /usr/bin: /usr/X 11 R 6/bin $PS 1 u@h: w$ $USER sgifford $HOSTNAME avocado. cslab. vt. edu $PWD /home/grads/sgifford n (C) Doug Bowman, Virginia Tech, 2001 8
Setting environment variables n Set a variable with <name>=<value> n Examples: n n n n TERM=vt 100 PS 1=myprompt> PS 1=$USER@$HOSTNAME: PS 1=“multiple word prompt> “ PATH=$PATH: $HOME/bin PATH=$PATH: ~ DATE=`date` (C) Doug Bowman, Virginia Tech, 2001 9
Aliases n n n Aliases are used as shorthand for frequentlyused commands Syntax: alias <shortcut>=<command> Examples: n n n alias alias ll=“ls -l. F” la=“ls -la” m=more up=“cd. . ” prompt=“echo $PS 1” (C) Doug Bowman, Virginia Tech, 2001 10
Repeating commands n n Use history to list the last 16 commands Use fc -l <m> <n> to list previously typed commands m through n (C) Doug Bowman, Virginia Tech, 2001 11
Editing on the command line n n Some command lines can be very long and complicated - if you make a mistake you don’t want to start all over again You can interactively edit the command line in several ways if using ksh n n set -o vi allows you to use vi commands to edit the command line set -o vi-tabcomplete also lets you complete commands/filenames by entering a TAB (C) Doug Bowman, Virginia Tech, 2001 12
Login scripts n n You don’t want to enter aliases, set environment variables, set up command line editing, etc. each time you log in All of these things can be done in a script that is run each time the shell is started (C) Doug Bowman, Virginia Tech, 2001 13
Login scripts (continued) n For bash, order of files is: n n n /etc/profile ~/. bash_login ~/. profile After logout n ~/. bash_logout (C) Doug Bowman, Virginia Tech, 2001 14
Example. bash_profile (partial) #. bash_profile: executed by bash(1) for login shells umask 022 # include. bashrc if it exists if [ -f ~/. bashrc ]; then source ~/. bashrc fi # some ls aliases alias ll='ls -l' alias la='ls -A' alias l='ls -CF' (C) Doug Bowman, Virginia Tech, 2001 15
Login scripts (continued) n For ksh, login shells execute: n n ~/. profile If ENV is set: n n That file is executed for each new terminal Example: ENV=$HOME/. kshrc EXPORT ENV (C) Doug Bowman, Virginia Tech, 2001 16
Background processing n n n Allows you to run your programs in the background sgifford@avocado: ~/cs 2204/$ emacs vi_practice_edited & sgifford@avocado: ~/cs 2204/$ (C) Doug Bowman, Virginia Tech, 2001 17
stdin, stdout, and stderr n stdout Each shell (and in fact all programs) automatically open three “files” when they start up n n n Standard input (stdin): Usually from the keyboard Program Standard output (stdout): Usually command to the terminal Standard error (stderr): Usually to the terminal stdin n Programs use these three files when reading (e. g. cin, writing (e. g. cout), or reporting errors/diagnostics (C) Doug Bowman, Virginia Tech, 2001 18
- Shell cleanliness shell soundness shell
- Shell membrane of egg
- The shell interpretive cycle in unix
- The shell interpretive cycle in unix
- Physics 2204 unit 3: work, power, energy
- 2204 b başvuru
- Tübitak 2204-b proje örnekleri matematik
- Cs 2204
- For todays meeting
- Today meeting or today's meeting
- What is meeting and types of meeting
- What is meeting and types of meeting
- International business and globalisation
- Virtualized environment
- What are the objectives of business environment
- Chapter 13 natural environments of europe
- Peng cui tsinghua
- Psychologically informed environments
- Psychologically informed environments