LINUX System : Lecture 5 (English-Only Lecture)

Slides:



Advertisements
Similar presentations
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Advertisements

More Shell Programming Software Tools. Slide 2 Keyword Shell Variables l The shell sets keyword shell variables. You can use (and change) them. HOME The.
Basics of Shell Programming. What’s Shell? It’s acts an interface between the user and OS (kernel).It’s known as “ command interpreter”. When you type.
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
More about Shells1-1 More about Shell  Shells (sh, csh, ksh) are m Command interpreters Process the commands you enter m High-level programming languages.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Integer variables #!/bin/csh # sum of numbers from $argv[1] to $argv[2] set low = $argv[1] set high = $argv[2] set sum = 0 set current = $low while ( $current.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang
Scripting Languages and C-Shell. What is a scripting language ? Script is a sequence of commands written as plain text and run by an interpreter (shell).
More Shell Programming Learning Objectives: 1. To learn the usage of environment (shell) variables in shell programming 2. To understand the handling of.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Shell Scripts 4 A shell usually interprets a single line of input, but we can also create a file containing a number of lines of commands to be interpreted.
Further Shell Scripting Michael Griffiths Corporate Information and Computing Services The University of Sheffield
Using Unix Shell Scripts to Manage Large Data
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
Nic Shulver, Scripts and Batch files Scripting in Windows and Linux What is scripting? What is it for? DOS/Windows batch files.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Introduction to Shell Script Programming
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Chapter 6: Shell Programming
An Introduction to Unix Shell Scripting
Writing C-shell scripts #!/bin/csh # Author: Ken Berman # Date: # Purpose: display command and parameters echo $0 echo $argv[*]
July 17, 2003Serguei A. Mokhov, 1 Shells and Shell Scripts COMP 444/5201 Revision 1.3 January 25, 2005.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
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.
1 Shell Scripting (C shell) SungHo Maeung 10/27/2000 Tutorial section Computer Science Lab.
Lecture 4  C Shell Scripts(Chapter 10). Shell script/program  Shell script: a series of shell commands placed in an ASCII text file  Commands include.
LINUX System : Lecture 6 Shell Programming
Keyword Shell Variables The shell sets keyword shell variables. You can use (and change) them. HOME The path to your home directory PATH Directories where.
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 11: Shell.
CS465 - UNIX The Bourne Shell.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
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.
1 Applied CyberInfrastructure Concepts ISTA 420/520 Fall Nirav Merchant Bio Computing & iPlant Collaborative Eric Lyons.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
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 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
Module 1 - Introduction to Linux. Users must log-in Linux is case sensitive File and Directories naming conventions (No spaces!) Files and Directories.
1 Writing Shell Scripts Professor Ching-Chi Hsu 1998 年 4 月.
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.
Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 12 Dr. Jerry Shiao, Silicon Valley University.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
By Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
CS 350 Lecture 3 UNIX/Linux Shells by İlker Korkmaz and Kaya Oğuz.
CIRC Winter Boot Camp 2017 Baowei Liu
Lecture 7 Introduction to Shell Programming
SUSE Linux Enterprise Desktop Administration
Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
CAP652 Lecture - Shell Programming
Unix Shells.
Some Linux Commands.
Shell Script Assignment 1.
Shell Environments.
CSCI The UNIX System Shell Startup and Variables
Introduction to Linux/UNIX
Shell Programming.
Linux Shell Script Programming
Bash Scripting CS 580U - Fall 2018.
Review.
CMPSC 60: Week 5 Discussion
Presentation transcript:

LINUX System : Lecture 5 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement : (i) wikipedia.org , (ii) http://www.doc.ic.ac.uk/~wjk/UnixIntro

Shell Variables Environment Variables (Global) environment variable Used to provide information to programs (Global) environment variable New programs and shells inherit environment variables from their parent shell Local shell variable Used only by that shell Not passed to other processes

Environment Variables “env” or “printenv” command Display current environment variables DISPLAY The graphical display to use, e.g. nyssa:0.0 EDITOR The path to your default editor, e.g. /usr/bin/vi GROUP Your login group, e.g. staff HOME Path to your home directory, e.g. /home/frank HOST The hostname of your system, e.g. nyssa IFS Internal field separators, usually any white space (defaults to tab, space and <newline>) LOGNAME The name you login with, e.g. frank PATH Paths to be searched for commands, e.g. /usr/bin:/usr/ucb:/usr/local/bin PS1 The primary prompt string, Bourne shell only (defaults to $) PS2 The secondary prompt string, Bourne shell only (defaults to >) SHELL The login shell you're using, e.g. /usr/bin/csh TERM Your terminal type, e.g. xterm USER Your username, e.g. frank

Set Shell Variables Mostly set automatically when log in setenv set $ setenv NAME value # in C Shell set $ set name = value # in C Shell

Shells scripts Any collection of shell commands can be stored in a file called a shell script. Scripts have variables and flow control statements like other programming languages. There are two popular classes of shells: C shell (csh) and variants (tcsh) Bourne shell (sh) and variants (bash, ksh)

Invoking scripts There are two ways to launch scripts: 1) Direct interpretation csh scriptfile [args …] 2) Indirect interpretation The first line of the file must be #!/bin/csh and the file must be executable. C Shell

Variables To set variables: set X [= value] Variable contents are accessed using ‘$’: echo $PATH To count the number of variable elements: echo $#Y C Shell

Variables cont’d To create lists: set Y = (abc 1 123) To set a list element: set Y[2] = 3 To view a list element: echo $Y[2] C Shell

Command arguments A shell script to swap files: #! /bin/csh –f set tmp = $argv[1] cp $argv[2] $argv[1] cp $tmp $argv[2] The number of arguments to a script: $#argv C Shell

if-then-else if ( expr ) simple-command if ( expr ) then commandlist-1 endif C Shell

if-then-else cont’d An example: if ($#argv <> 2) then echo “we need two parameters!“ else set name1 = $argv[1] set name2 = $argv[2] endif C Shell

Loops while ( expr ) commandlist end foreach var ( worddlist ) C Shell

switch C Shell switch ( str ) case string1: commandlist1 breaksw default commandlist endsw C Shell

goto (Considered harmful!) To jump unconditionally: goto label A label is a line such as: label: The classic paper on why not to use goto: Go To Statement Considered Harmful Edsger W. Dijkstra, CACM, March 1968 C Shell

An example script C Shell #! /bin/csh -f foreach name ($argv) if ( -f $name ) then echo -n "delete the file '${name}' (y/n/q)?" else echo -n "delete the entire dir '${name}' (y/n/q)? " endif set ans = $< # $< means “read a line” switch ($ans) case n: continue case q: exit case y: rm -r $name; continue endsw end C Shell