UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.

Slides:



Advertisements
Similar presentations
Lesson-4 The Shell as Interpreter
Advertisements

1 UNIX System Programming Introduction. 2 Outline UNIX History UNIX Today? UNIX Processes and the Login Process Shells: Command Processing, Running Programs.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
The Linux Shell The shell contains
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
Linux+ Guide to Linux Certification, Second Edition
CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
Shell Script Examples.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Introduction to UNIX Don Bahls user consultant (907)
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.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University.
CS 2061 Shells Also known as: Unix Command Interpreter.
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.
Workbook 6 – Part 1 The Bash Shell
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
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
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
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.
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
INFO 320 Server Technology I Week 5 Shell environments and scripting 1INFO 320 week 5.
Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi.
Chapter Four I/O Redirection1 System Programming Shell Operators.
Unix Shell Environments February 23rd, 2004 Class Meeting 6.
I/O Redirection & Regular Expressions CS 2204 Class meeting 4 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
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.
Introduction to Programming Using C An Introduction to Operating Systems.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
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.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Introduction to UNIX CS 2204 Class meeting 1 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
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.
Linux+ Guide to Linux Certification, Second Edition
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Linux Administration Working with the BASH Shell.
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.
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
System Programming and administration CS 308
The Linux Operating System
Shell Environments.
CSE 303 Concepts and Tools for Software Development
UNIX and Shell Programming (06CS36)
John Carelli, Instructor Kutztown University
Shell Commands Using BASH Copyright © 2017 Curt Hill.
Shell Programming.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Unix Shell Environments
Chapter 3 The UNIX Shells
Presentation transcript:

UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002

(C) Doug Bowman, Virginia Tech, Shell characteristics Command line interface between the user and the system Is simply a program that automatically starts when you login Waits for user to type in commands

(C) Doug Bowman, Virginia Tech, Main shell features Interactivity aliases file-name completion Scripting language Allows programming (shell scripting) within the shell environment Uses variables, loops, conditionals, etc. Next lecture

(C) Doug Bowman, Virginia Tech, Various UNIX shells sh (Bourne shell, original UNIX shell) ksh (Korn shell) csh (C shell, developed at Berkeley) tcsh bash (Bourne again SHell) … Differences mostly in level of interactivity support and scripting details

(C) Doug Bowman, Virginia Tech, The Bourne again SHell (bash) We will be using bash as the standard shell for this class This will be important for shell scripting assignments Superset of the Bourne shell (sh) Borrows features from sh, csh, tcsh & ksh Created by Free Software Foundation

(C) Doug Bowman, Virginia Tech, Changing your shell On most UNIX machines: which bash (note path) chsh On the lab machines: which ksh (note path /bin/bash) ypchsh

(C) Doug Bowman, Virginia Tech, Environment variables A set of variables the shell uses for certain operations Variables have a name and a value Current list can be displayed with the env command A particular variable’s value can be displayed with echo $

(C) Doug Bowman, Virginia Tech, Some Environment variables Some interesting variables: HOME, PATH, PS1, USER, HOSTNAME, PWD $HOME /home/gradstudents/m/miali $PATH /usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin $PS1 $USER miali $HOSTNAME avocado.cslab.vt.edu $PWD /home/gradstudents/m/miali

(C) Doug Bowman, Virginia Tech, Setting environment variables Set a variable with = Examples: TERM=vt100 PS1=myprompt> PS1=“multiple word prompt> “ PATH=$PATH:$HOME/bin DATE=`date`

(C) Doug Bowman, Virginia Tech, Aliases Aliases are used as shorthand for frequently- used commands Syntax: alias = Examples: alias ll=“ls -lF” alias la=“ls -la” alias m=more alias up=“cd..” alias prompt=“echo $PS1”

(C) Doug Bowman, Virginia Tech, Repeating commands Use history to list the last 16 commands Use fc -l to list previously typed commands m through n

(C) Doug Bowman, Virginia Tech, Editing on the command line Some command lines can be very long and complicated - if you make a mistake you don’t want to start all over again You can interactively edit the command line in several ways set -o vi allows you to use vi commands to edit the command line set -o vi-tabcomplete also lets you complete commands/filenames by entering a TAB

(C) Doug Bowman, Virginia Tech, Login scripts You don’t want to enter aliases, set environment variables, set up command line editing, etc. each time you log in All of these things can be done in a script that is run each time the shell is started

(C) Doug Bowman, Virginia Tech, Login scripts (continued) For bash, order of files is: /etc/profile ~/.bash_profile ~/.bash_login ~/.profile After logout ~/.bash_logout

(C) Doug Bowman, Virginia Tech, Example.bash_profile (partial) #.bash_profile: executed by bash(1) for login shells umask 022 # include.bashrc if it exists if [ -f ~/.bashrc ]; then source ~/.bashrc fi # some ls aliases alias ll='ls -l' alias la='ls -A' alias l='ls -CF'

(C) Doug Bowman, Virginia Tech, stdin, stdout, and stderr Each shell (and in fact all programs) automatically open three “files” when they start up Standard input (stdin): Usually from the keyboard Standard output (stdout): Usually to the terminal Standard error (stderr): Usually to the terminal Program command stdin stdout Programs use these three files when reading (e.g. cin, writing (e.g. cout ), or reporting errors/diagnostics

(C) Doug Bowman, Virginia Tech, Redirecting stdout Instead of writing to the terminal, you can tell a program to print its output to another file using the > operator >> operator is used to append to a file Examples: man ls > ls_help.txt Echo $PWD > current_directory cat file1 >> file2

(C) Doug Bowman, Virginia Tech, Redirecting stdout cat file1.txt This is a small test file. cat file1.txt> file2.txt cat file2.txt This is a small test file.

(C) Doug Bowman, Virginia Tech, Redirecting stdin Instead of reading from the terminal, you can tell a program to read from another file using the < operator Examples: Mail < message.txt a.out < testdata1.txt

(C) Doug Bowman, Virginia Tech, Background processing Allows you to run your programs in the background emacs vi_practice_edited &

(C) Doug Bowman, Virginia Tech, Pipes and filters Pipe: a way to send the output of one command to the input of another Filter: a program that takes input and transforms it in some way wc - gives a count of words/lines/chars grep - searches for lines with a given string more sort - sorts lines alphabetically or numerically

(C) Doug Bowman, Virginia Tech, Examples of wc wc file1.txt file1.txt wc file1.txt file2.txt file1.txt file2.txt total

(C) Doug Bowman, Virginia Tech, Examples of filtering ls -la | wc man ksh | grep “history\.” The name of the file used to store history. When first and last select commands from the history. Moves to the beginning of the history. Moves to the end of the history. history or search-history. move to the nth next line in the history. through the history.

(C) Doug Bowman, Virginia Tech, More Examples ls -al |grep bash -rw miali grads 5427 May 29 08:36.bash_history -rw-r--r-- 1 miali grads 174 May 16 02:00.bash_logout -rw-r--r-- 1 miali grads 519 May 16 02:00.bash_profile -rw-r--r-- 1 miali grads 1115 May 29 08:36.bashrc -rw-r--r-- 1 miali grads 1116 May 29 08:33.bashrc~ -rw-r--r-- 1 miali grads 876 May 16 02:00.bashrc.dpkg- old ls -al |grep bash |wc