130 likes | 314 Views
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
E N D
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
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
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
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
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
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
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
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
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
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
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
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
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