cis 118 intro to unix
play

CIS 118 Intro to UNIX Bourne Again Shell (BASH) CIS 118: Intro to - PowerPoint PPT Presentation

CIS 118 Intro to UNIX Bourne Again Shell (BASH) CIS 118: Intro to UNIX Shell Characteristics Command-line interface between the user and the system Automatically starts when you log in, waits for user to type in commands A


  1. CIS 118 – Intro to UNIX  Bourne Again Shell (BASH) CIS 118: Intro to UNIX

  2. Shell Characteristics  Command-line interface between the user and the system  Automatically starts when you log in, waits for user to type in commands  A Unix shell is both a command interpreter, which provides the user interface to the rich set of utilities, and a programming language, allowing these utilities to be combined. CIS 118: Intro to UNIX

  3. Main Shell Features  Interactivity  Aliases  File-name completion  Scripting language  Allows programming (shell scripting) within the shell environment  Uses variables, loops, conditionals, etc.  Next lecture CIS 118: Intro to UNIX

  4. Various Unix Shells  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 http://www.faqs.org/faqs/unix-faq/shell/shell-differences/ CIS 118: Intro to UNIX

  5. Bourne Again SHell  We will be using bash as the standard shells for this class  Superset of the Bourne shell (sh)  Borrows features from sh, csh, tcsh, and ksh  Created by the Free Software Foundation CIS 118: Intro to UNIX

  6. Changing Your Shell  On most Unix machines (including the lab) . . .  which bash  chsh  On some machines . . .  Ypchsh CIS 118: Intro to UNIX

  7. Environment Variables  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> CIS 118: Intro to UNIX

  8. Environment Variable Examples  Some interesting environment variables:  $HOME /home/grads/callgood  $PATH /usr/local/bin:/bin:/usr/bin:/us r/X11R6/bin  $PS1 \u@\h:\w\$  $USER callgood  $HOSTNAME mango.cslab.vt.edu  $PWD /home/grads/callgood/cs2204 CIS 118: Intro to UNIX

  9. Setting Environment Variables  Set a variable with <name>=<value>  Examples:  PS1=myprompt>  PS1=$USER@$HOSTNAME:  PS1=“multiple word prompt> ”  PATH=$PATH:$HOME/bin  PATH=$PATH:~  DATE=`date` CIS 118: Intro to UNIX

  10. Aliases  Aliases are used as shorthand for frequently-used commands  Syntax: alias <shortcut>=<command>  Examples:  alias ll=“ls –lF”  alias la=“ls –la”  alias m=more  alias up=“cd ..”  alias prompt=“echo $PS1” CIS 118: Intro to UNIX

  11. Repeating Commands  Use history command to list previously entered commands  Use fc – l <m> <n> to list previously typed commands from m through n CIS 118: Intro to UNIX

  12. Editing on the Command Line  bash provides a number of line editing commands; many are the same as emacs editing commands  M-b Move back one word  M-f Move forward one word  C-a Move to beginning of line  C-e Move to end of line  C-k Kill text from cursor to end of line CIS 118: Intro to UNIX

  13. Login Scripts  You don’t want to enter aliases, set environment variables, 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 CIS 118: Intro to UNIX

  14. Login Scripts (cont)  For bash, order is . . .  /etc/profile  ~/.bash_profile  ~/.bash_login (if no .bash_profile)  ~/.profile (if neither are present)  ~/.bashrc  After logout . . .  ~/.bash_logout CIS 118: Intro to UNIX

  15. Example .bash_profile (partial) # .bash_profile # include .bashrc if it exists if [ -f ~/.bashrc ]; then . ~/.bashrc fi # Set variables for a warm fuzzy environment export CVSROOT=~/.cvsroot export EDITOR=/usr/local/bin/emacs export PAGER=/usr/local/bin/less CIS 118: Intro to UNIX

  16. Example .bashrc (partial) # .bashrc # abbreviations for some common commands alias f=finger alias h=history alias j=jobs alias l='ls -lF' alias la='ls -alF' alias lo=logout alias ls='ls -F' CIS 118: Intro to UNIX

  17. Login Shell login shell /etc/profile ~/.bash_profile interactive shell ~/.bashrc ~/.bashrc interactive shell interactive shell ~/.bashrc ~/.bashrc CIS 118: Intro to UNIX

  18. Background Processing  Allows you to run your programs in the background callgood@mango:~/$ emacs textfile& callgood@mango:~/$ CIS 118: Intro to UNIX

  19. stdin, stdout, and stderr  Each shell (and in fact all programs) automatically open three “files” when they start up  Standard input (stdin): Usually from the keyboard  Standard output (stdout): Usually to the terminal  Standard error (stderr): Usually to the terminal  Programs use these three files when reading (e.g. cin), writing (e.g. cout), or reporting errors/diagnostics CIS 118: Intro to UNIX

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend