Introduction to Unix Shell - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Introduction to Unix Shell

Description:

... Shell can do. Customization of a Unix session. Scripting. Types ... C shell : csh, tcsh. better for user customization and scripting %, for command prompt ... – PowerPoint PPT presentation

Number of Views:144
Avg rating:3.0/5.0
Slides: 20
Provided by: a15220
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Unix Shell


1
Introduction to Unix Shell Scripting with
csh/tcsh
  • Brief Unix History
  • Unix Shell Flavor
  • CSH/TCSH Scripts

2
Unix Architecture
3
What is Shell?
  • Shell is
  • Command Interpreter that turns text that you type
    (at the command line) in to actions
  • User Interface take the command from user
  • Programming Shell can do
  • Customization of a Unix session
  • Scripting

4
Types of Shells
  • Interactive vs. Non-interactive login or not
  • Interactive login shell started after login
  • Non-interactive shell
  • Present when shell script is running
  • Just inherits parents environment
  • Interactive non-login shell started
  • Started from a command line
  • Copies parent environment then invokes
    /.bash_rc (or /.cshrc or /.tcshrc)

5
Popular Shells
  • sh Bourne Shell
  • ksh Korn Shell
  • csh,tcsh C Shell (for this course)
  • bash Bourne-Again Shell

6
Flavors of Unix Shells
  • Two main flavors of Unix Shells
  • Bourne (or Standard Shell) sh, ksh, bash, zsh
  • Fast
  • for command prompt
  • C shell csh, tcsh
  • better for user customization and scripting
  • , gt for command prompt
  • To check shell
  • echo SHELL (shell is a pre-defined variable)
  • To switch shell
  • exec shellname (e.g., exec bash)

7
Startup files
  • sh,ksh
  • /etc/profile (out-of-the-box login shell
    settings)/etc/profile.local (addtnl. local
    system settings)/.profile (addtnl. user
    customized settings)/.kcshrc (non-login shell
    user customization)
  • bash/etc/profile (out-of-the-box login shell
    settings) /etc/bash.bashrc (out-of-box non-login
    settings)/etc/bash.bashrc.local (global
    non-login settings)
  • /.bash_profile (login shell user
    customization)
  • /.bashrc (non-login shell user customization)
  • /.bash_logout (user exits from interactive
    login shell)
  • csh/tcsh/etc/login (out-of-the-box login shell
    settings)/etc/csh.login (non-login shell
    customizations)/etc/csh.login.local (global
    non-login settings)
  • /.login (login shell user customizations)
  • /.cshrc (non-login shell user customizations)
  • /.cshrc.logout (non-login shells at logout)
  • /.logout (read by login shells at logout)

8
Some Special Keys Under tcsh
  • Ctrl-U Delete everything on the command-line
  • Ctrl-A Move cursor to the front
  • Ctrl-E Move cursor to the end
  • Ctrl-P Set the current command-line to the
    previous command
  • Ctrl-N Set the current command-line to the next
    command
  • TAB Filename completion

9
What shell am I running?
Use the echo command to learn the value of SHELL
environment variable
Issue a ps command to see all the processes in
your currentlogin session
10
What about my default shell?
Use the echo command to learn the value of your
default shell
Use the finger command to learn anyones default
shell
View the /etc/passwd file to learn login shells
and more
Use the grep command to search for a string in a
file
To change the your default shell, e-mail the
systems administrator (e.g., root_at_willow.olemiss.
edu) and specifythe name of the shell that you
want.
11
Its Not Too Late to Change Your Current Shell
Use exec ltshell namegt to switch to a different
shell
Issue a ps command to see all the processes in
your currentlogin session
12
More with processes
Issue a ps command to see all the processes in
your currentlogin session
Issue a ps u USER command to see all your
processes, across all login sessions
Use kill to terminate processes that have gone
rogue
13
More with processes
Issue a ps -aef command to everyones processes
Pipe ps out put to more command to view page at a
time
14
Environment Variables
Use the env command to see all environment
variables set to see all shell
variables http//docs.hp.com/en/B2355-90046/ch10s0
4.html
Set or change environment variables from the
command-linenew values last only for current
login session. sh/bash/ksh set
NEW_VARIABLEnewvalue append OLD_VARIABLE
OLD_VARIABLEnewvalue prepend
OLD_VARIABLEnewvalueOLD_VARIABLE csh/tcsh
set set NEW_VARnewvalue append set
OLD_VAR(OLD_VAR newvalue) prepend set
OLD_VAR(newvalue OLD_VAR) set
setenv OLD_VAR newvalue append setenv OLD_VAR
OLD_VARnewvalue prepend setenv OLD_VAR
newvalueOLD_VAR
15
Practice Setting Env. Variables
Change the PROMPT environment variable
Update the PATH environment variable to include
your numbered subdirectory
16
Aliases
Use the alias command to create shorthand for
longer commands
17
Command History
Your most recent commands are logged in one or
more hidden files, which you may browse to keep
from having to retypecommands.
You can set environment variables to configure
how many commands are remembered in the current
login session (history), how many commands are
remembered after you logout (savehist), and the
name of the file where thesecommands are stored
(.history).
You can browse history commands from the command
line.
18
Customization of a Session
  • Each shell supports some customization.
  • User prompt
  • Where to find mail
  • Shortcuts (alias)
  • The customization takes place in startup files
  • Startup files are read by the shell when it
    starts up
  • The Startup files can differ for different shell

19
Examine Startup files
  • sh,ksh
  • /etc/profile (out-of-the-box login shell
    settings)/etc/profile.local (addtnl. local
    system settings)/.profile (addtnl. user
    customized settings)/.kcshrc (non-login shell
    user customization)
  • bash/etc/profile (out-of-the-box login shell
    settings) /etc/bash.bashrc (out-of-box non-login
    settings)/etc/bash.bashrc.local (global
    non-login settings)
  • /.bash_profile (login shell user
    customization)
  • /.bashrc (non-login shell user customization)
  • /.bash_logout (user exits from interactive
    login shell)
  • csh/tcsh/etc/login (out-of-the-box login shell
    settings)/etc/csh.login (non-login shell
    customizations)/etc/csh.login.local (global
    non-login settings)
  • /.login (login shell user customizations)
  • /.cshrc (non-login shell user customizations)
  • /.cshrc.logout (non-login shells at logout)
  • /.logout (read by login shells at logout)
Write a Comment
User Comments (0)
About PowerShow.com