1 / 19

Introduction to Unix Shell & Scripting with csh / tcsh

Introduction to Unix Shell & Scripting with csh / tcsh. Brief Unix History Unix Shell & Flavor CSH/TCSH Scripts. Unix Architecture. 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

Mercy
Download Presentation

Introduction to Unix Shell & Scripting with csh / tcsh

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. 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 parent’s 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 • %, > 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 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 To change the your default shell, e-mail the systems administrator (e.g., root@willow.olemiss.edu) and specifythe name of the shell that you want.

  11. Its Not Too Late to Change Your Current Shell Use exec<shell name> 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 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 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)

More Related