1 / 13

Unix Comp-145

Unix Comp-145. Lecture 6: Customizing the Shell Environment Text: S. Das, “Your Unix: The ultimate Guide”, 2 nd Edition, McGraw Hill, 2006. Unix Operating System. Different Shell Types and Their Properties How Shell Operates on a Command Line Environmental Variables

tamyra
Download Presentation

Unix Comp-145

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix Comp-145 Lecture 6: Customizing the Shell Environment Text: S. Das, “Your Unix: The ultimate Guide”, 2nd Edition, McGraw Hill, 2006 BROOKDALE COMMUNITY COLLEGE

  2. Unix Operating System Different Shell Types and Their Properties How Shell Operates on a Command Line Environmental Variables Aliases & Other Shell Features Use Of .profile&.envFiles Use of Pipe Facility to Create New Functions BROOKDALE COMMUNITY COLLEGE

  3. Different Shell Types & their Properties • Interactive Shell • On login • Prompts ($) and waits for your response/requests • Supports Job Control, aliases and history • NonInteractive Shell • Executes a shell script • All features of Shell Script can be used in interactive Shells too BROOKDALE COMMUNITY COLLEGE

  4. How Shell Operates on a Command Line Shell interpreter parses content line by line Shell interpreter invokes sub-shells Interpreter converts text into executable binary code. Executes initialization scripts, e.g., .profile BROOKDALE COMMUNITY COLLEGE

  5. Shells • Present a customizable environment • Interprets meta characters • Createshortcuts • Manipulate shell variables • Invokes Kernal commands • Supports both: • Interactive (e.g., login) and • Noninteractive shells (e.g., shell scripts) BROOKDALE COMMUNITY COLLEGE

  6. Environmental Variables • 2 types • Local • Values not available to child processes • Assigned with command set • Environment – Available to user’s total environment • PATH • HOME • SHELL • Displaying currently assigned variable • $ set - Commanddisplays both env + local variables BROOKDALE COMMUNITY COLLEGE

  7. Environmental Variables (cont’d) • Creating a variable • $ variable=value [local variable until exported] • NOTE: “=“ assigns values to variables • Example: $ H=$HOME • Making a Local variable into an Environment variable • $ export COMMAND • Once exported, becomes Environment Variable BROOKDALE COMMUNITY COLLEGE

  8. Environmental Variables (cont’d) • Useful Variables • $ H=$HOME$ export H • (sets the Environment variable $HOME to a shorter string) • $ PS1='$PWD -> '$ export PS1 • (sets the first prompt string (PS1) to tell you the current directory and changes the prompt from $ to: the name of the current directory ($PWD) BROOKDALE COMMUNITY COLLEGE

  9. Aliases • Assigns shorthand names to commands • alias commandname=“command [options]” • alias ..=“cd ..” • alias search=grep • alias  rm="rm  -I” • No whitespace around “=“ • Useunaliascommandnameto unset assignment • Use alias to display all assigned aliases • Aliases in shells expanded before executed • Aliases not supported in Bourne Shell BROOKDALE COMMUNITY COLLEGE

  10. Aliases (Cont’d) • aliasmycommand=UNIXcommand • alias search=grep • alias  rm="rm  -i" • Alias put in .profilenot exported to sub-shells • Better to put in .envfile and have .profile invoke it, e.g., • $ ENV=~/.env$ export ENV$ . $ENV BROOKDALE COMMUNITY COLLEGE

  11. Aliases (cont’d) • Useful Command • whencecmdname • Checks whether the alias "took” • returns the pathname when cmdname is the name of a script or executable program, or the command executed when it's an alias. • Special characters for alias available in C-Shell only • \!*means all arguments in the command line • \!$means the last argument in the commandline BROOKDALE COMMUNITY COLLEGE

  12. Other Shell Features • SIGNALS: • Specifies a symbolic name/number specifying the signal to be sent instead of the default TERM • Used by Kernal to communicate with a process • kill –s signalName PID or • kill –signalName PID • generated through your keyboard • Commonly used signal numbers & signalNames • 1 HUP (hang up) • INT (interupt) • QUIT (quit) • ABRT (abort) • 9 KILL (non-catchable, non-stoppable) • 14 ALRM (alarm clock) • Send HangUp signal to PID #5167: kill –s HUP 507 BROOKDALE COMMUNITY COLLEGE

  13. Other Shell Controls • Useful Commands • set –o option_name • Option_Names: noclobber, ignoreeof, etc. • set –o notify - causes kernal to notify immediately when background stops. • set –o ignoreeof- causes kernal not to end login session on receipt of [Ctl-d]. • unset –o option_nameor set +o option_name • Option_Names: noclobber, ignoreeof, etc. BROOKDALE COMMUNITY COLLEGE

More Related