CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang

Slides:



Advertisements
Similar presentations
Bash startup files Linux/Unix files stty 1.  midterms  bash startup files  stty 2.
Advertisements

Chapter 9: The TC Shell Everything you thought you knew is now wrong.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 32: - Shell Programming Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
CS 497C – Introduction to UNIX Lecture 34: - Shell Programming Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Using the Bash Shell. Linux Shell Options Linux provides a range of options for shells. bash –The GNU Bourne Again Shell (bash) bsh – The Bourne Shell.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Introduction to Shell Script Programming
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter 6: Shell Programming
An Introduction to Unix Shell Scripting
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
Workbook 6 – Part 1 The Bash Shell
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Linux+ Guide to Linux Certification, Third Edition
Basic Shell Scripting - Part 1 Objective - Learn to: Read Start-up Files Edit Start-up Files Modify Your User Environment Communicate with Users Write.
CS465 - UNIX The Bourne Shell.
Workbook 6 – Part 2 The Bash Shell
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
UNIX/LINUX SHELLS.  “A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and.
Introduction to Unix Shell & Scripting with csh/tcsh  Brief Unix History  Unix Shell & Flavor  CSH/TCSH Scripts.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi.
June 1, 1999Customizing the UNIX Environment1 Introduction to UNIX G. Customizing the UNIX Environment.
Unix Shell Environments February 23rd, 2004 Class Meeting 6.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
User Environments Objectives –to provide appropriate environments for different types of users Contents –different login programs –user profiles –restricted.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This.
Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Chapter 8: The Bourne Again Shell It’s a command interpreter, it’s a programming language, and it makes a mean martini.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Comp 145 – Introduction to UNIX $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 UNIX Processes.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Shells.
SUSE Linux Enterprise Desktop Administration
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
System Programming and administration CS 308
CAP652 Lecture - Shell Programming
LINUX System : Lecture 5 (English-Only Lecture)
Shell Environments.
UNIX and Shell Programming (06CS36)
John Carelli, Instructor Kutztown University
CSCI The UNIX System Shell Startup and Variables
Shell Programming.
Linux Shell Script Programming
Unix Shell Environments
Chapter 3 The UNIX Shells
Presentation transcript:

CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang

Which Shell? A command in one shell may either not be available in another or behave in a different manner. You can ask the system administrator to set your login shell. If your system supports the chsh command, you can do that yourself. In our department, ypchsh is used instead of chsh. ypchsh is used change your password in the NIS database.

Which Shell? The Network Information Service (NIS) is an administrative database that provides central control and automatic dissemination of important administrative files. NIS converts several standard UNIX files into databases that can be queried over the network. The databases are called NIS Maps. The advantage of using NIS is that these important administrative files can be maintained on a central server, and yet completely accessible to every workstation on the network.

Which Shell? Let’s select Korn as our login shell: % ypchsh Changing NIS account information for cs497c on bentley. Please enter password: Changing login shell for cs497c on bentley. To accept the default, simply press return. To use the system's default shell, type the word "none". Login shell [/bin/csh]: /usr/bin/ksh The login shell has been changed on bentley.

Which Shell? The Bourne shell (sh) is the first shell of the UNIX system and has the fewest features. The C shell (csh) introduced by Berkeley as a superior interpreter but an inferior programming language. The ksh93 version of the Korn shell (ksh) is superior to the other two and feature-rich. bash, the Bourne Again shell (bash) is the standard shell used by Linux systems.

Environment Variables An environment variable is a shell variable that is exported to make it available in all sub-shells. The behavior of the UNIX system is largely determined by the settings of these variables. The set statement displays a complete list of all variables. It’s the env command (or export statement) that shows only the environment variables.

Environment Variables Setting a variable to an environment variable in different shells is shown as follows: –Bourne shell: x=5; export x –C Shell: setenv x 20 –Korn Shell: export x=5 PATH is a system variable that contains a colon-delimited list of directories that the shell looks through to locate a command invoked by a user.

Significance of the Environment (System) Variables HOME shows your login directory. LOGNAME shows your username. MAIL shows the mailbox location. PS1 stores the primary prompt string. PS2 stores the secondary prompt string. CDPATH stores the directory search path. SHELL stores the shell you are using. TERM indicates the terminal type that is used.

Significance of the Environment (System) Variables The C Shell stores the prompt string in the prompt variable. The C Shell introduces a history feature that allows users to reexecute previous commands without reentering them. Every command in the history list has an event number. The C Shell uses path as the command search path.

Aliases All shells apart from Bourne support the use of aliases that let you assign shorthand names for frequently used command. Examples of using aliases in C Shell are shown in below: alias dir ls -l alias ls ls -Fax unalias dir

Aliases Using aliases in Korn Shell and bash is shown as follows: alias dir=‘ls -l’ alias ls=‘ls -Fax’ These shells also support a history feature that lets you recall previous commands (events), performing a substitution if necessary. The history command displays all events: % history

Command History (C Shell and bash) The ! command is used to repeat previous commands in C Shell. !! repeats previous command. !11 repeats event number 11. !-2 repeats the command before the last one. !v repeats last command beginning with v. !grep:s/William/Bill repeats previous grep command with Bill instead of William. ^bak^doc substitutes first instance of bak.

Command History (Korn Shell) Korn uses the r command to repeat previous commands. r repeats the last command. r 11 repeats the event number 11. r -2 repeats the command before the last one. r v repeats last command beginning with v. r grep William = Bill repeats previous grep command with Bill instead of William.

In-Line Command Editing in Korn Shell and bash You can perform vi and emacs like in-line editing of the command line by using set -o vi or set -o emacs. Suppose you chose vi. Press [Esc] to take you to vi’s Command Mode. You can use the /pattern sequence. Use i, a, A, and so forth to enter the Input Mode. Use set +o to turn off in-line editing.

Filename Completion Korn and bash support a feature called filename completion, which has been enhanced in the modern version of these shells to support. –Completion of a filename used as an argument to a command. –Completion of the command name itself. This means that you may not have to enter the complete command or filename.

Filename Completion To activate the completion in Korn Shell, use either one of them: set –o vi, EDITOR=vi, VISUAL=vi. To use the completion feature, we need just two commands; both require the [Esc] key. vi pl[Esc]\ use vi to edit the file planets. You can ask for the file list that matches the entered string by using [Esc]=. vi pl[Esc]=

Miscellaneous Features The C Shell uses the set statement with the noclobber argument to prevent accidental overwriting of files: set noclobber To override this protection feature, you have to use the !. set ignoreeof make [Ctrl-d] not log you out. In Korn shell and bash, you use: set –o noclobber

Miscellaneous Features The ~ acts as a shorthand representation of the home directory. cd ~juliet effectively becomes cd $HOME/juliet. We have assigned values to many environment variables, defined aliases and used set options. To make these settings permanent, you’ll have to place them in the system’s startup scripts.

The Initialization Scripts Every shell uses at least one startup script that is placed in the user’s home directory. Look in your home directory with ls –a, and you’ll find one or more of these files: –.profile (Bourne Shell) –.login,.cshrc and.logout (C Shell) –.profile and.kshrc (Korn Shell) –.bash_profile (or.profile or.bash_login ),.bashrc and.bash_logout (bash).

The Initialization Scripts A script can belong to one of three categories: –Login script – This is a startup script that is executed when a user logs in (.login,.profile and.bash_profile). –Environment script – This file is executed when a sub-shell is run from the login shell. It is often referred to as the rc script (.cshrc,.kshrc and.bashrc). –Logout script – Only the C shell and bash use a logout script (.logout and.bash_logout).

The Initialization Scripts There are two commands which run any shell script without creating a sub-shell – the. (dot) and source command. The C shell uses source, Bourne and Korn shell use the dot, and bash uses both. When you log in, you see an interactive shell that present a prompt and waits for your requests. When you execute a shell script, you call up a noninteractive shell.

The Initialization Scripts In the Bourne shell login, the shell executes these two files: /etc/profile and.profile in user’s home directory. In the C shell login, the shell runs three scripts in the order: /etc/login or /etc/.login, ~/.cshrc, and then ~/.login. In the Korn shell login, the scripts are executed in this order: /etc/profile, ~/.profile, and then ~/.kshrc.

The Initialization Scripts In the bash shell login, the scripts are executed in this order: /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile, and then ~/.bashrc.