Download presentation
Presentation is loading. Please wait.
Published byJean Wells Modified over 8 years ago
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: Command Interpreter that turns text that you type (at the command line) in to actions: User Interface: take the command from user User Interface: take the command from user Programming Shell can do Customization of a Unix session Customization of a Unix session Scripting 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 Present when shell script is running Just inherits parent’s environment Just inherits parent’s environment Interactive non-login shell started Started from a command line Started from a command line Copies parent environment then invokes ~/.bash_rc (or ~/.cshrc or ~/.tcshrc) 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 Bourne (or Standard Shell): sh, ksh, bash, zsh FastFast $ for command prompt$ for command prompt C shell : csh, tcsh C shell : csh, tcsh better for user customization and scriptingbetter for user customization and scripting %, > for command prompt%, > for command prompt To check shell: % echo $SHELL (shell is a pre-defined variable) % echo $SHELL (shell is a pre-defined variable) To switch shell: % exec shellname (e.g., % exec bash) % 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) ~/.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 current login session
10
What about my default shell? Use the echo command to learn the value of your default shell To change the your default shell, e-mail the systems administrator (e.g., root@willow.olemiss.edu) and specify the name of the shell that you want.root@willow.olemiss.edu Use the finger command to learn anyone’s 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
11
Its Not Too Late to Change Your Current Shell Use exec to switch to a different shell Issue a ps command to see all the processes in your current login session
12
More with processes Issue a ps command to see all the processes in your current login 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 everyone’s 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/ch10s04.html Set or change environment variables from the command-line: new values last only for current login session. sh/bash/ksh set: NEW_VARIABLE=newvalue append:OLD_VARIABLE=$OLD_VARIABLEnewvalue prepend: OLD_VARIABLE=newvalue$OLD_VARIABLE csh/tcsh set: set NEW_VAR=newvalue append: set OLD_VAR=($OLD_VAR newvalue) prepend: set OLD_VAR=(newvalue $OLD_VAR) set: setenv OLD_VAR newvalue append: setenv OLD_VAR ${OLD_VAR}newvalue prepend: setenv OLD_VAR newvalue${OLD_VAR}
15
Practice Setting Env. Variables Update the PATH environment variable to include your numbered subdirectory Change the PROMPT environment variable
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 retype commands. 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 these commands are stored (.history). You can browse history commands from the command line.
18
Customization of a Session Each shell supports some customization. User prompt User prompt Where to find mail Where to find mail Shortcuts (alias) Shortcuts (alias) The customization takes place in startup files Startup files are read by the shell when it starts up Startup files are read by the shell when it starts up The Startup files can differ for different shell 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) ~/.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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.