Chapter 9. Shell and Kernel

Similar documents
5/20/2007. Touring Essential Programs

Unix Shell Environments. February 23rd, 2004 Class Meeting 6

CST Algonquin College 2

System Programming. Unix Shells

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

Review of Fundamentals

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

EECS2301. Lab 1 Winter 2016

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Bourne Shell (ch 8) Overview. Bourne Shell. Bourne Shell. Bourne Shell. Bourne Shell. Redirect standard error. Redirect standard error

Standard. Shells. tcsh. A shell script is a file that contains shell commands that perform a useful function. It is also known as shell program.

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

Lecture 4. Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions?

Introduction to the Shell

Introduction: What is Unix?

Work Effectively on the Command Line

Introduction to Linux

UNIX System Programming Lecture 3: BASH Programming

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Using bash. Administrative Shell Scripting COMP2101 Fall 2017

Assignment clarifications

Shells and Shell Programming

Linux shell scripting Getting started *

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Useful Unix Commands Cheat Sheet

5/8/2012. Specifying Instructions to the Shell Chapter 8

COMP 4/6262: Programming UNIX

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Introduction to Shell Scripting

CS246 Spring14 Programming Paradigm Notes on Linux

Shells and Shell Programming

Log into Linux Reminders: Homework 1 due today; Homework 2 due on Thursday Questions?

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

Vi & Shell Scripting

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Introduction to UNIX Part II

Processes and Shells

Lecture 8. Introduction to Shell Programming. COP 3353 Introduction to UNIX

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

Command-line interpreters

Unix Shells and Other Basic Concepts

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

Topic 2: More Shell Skills

85321, Systems Administration Chapter 6: The shell

Linux Command Line Interface. December 27, 2017

UNIX shell scripting

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

SANJAY GHODAWAT POLYTECHNIC

PROGRAMMAZIONE I A.A. 2015/2016

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

SOFTWARE ARCHITECTURE 3. SHELL

Perl and R Scripting for Biologists

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

UNIX Shell Programming

UNIX Kernel. UNIX History

CSCI2467: Systems Programming Concepts

Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

Linux 系统介绍 (III) 袁华

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

BASH SHELL SCRIPT 1- Introduction to Shell

Bash Guide for Beginners

Shell Programming Systems Skills in C and Unix

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Software I: Utilities and Internals. What isbash?

CSE II-Sem)

Introduction of Linux

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell.

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

D. Delete the /var/lib/slocate/slocate.db file because it buffers all search results.

Linux shell programming for Raspberry Pi Users - 2

Advanced training. Linux components Command shell. LiLux a.s.b.l.

Basics. I think that the later is better.

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

The Command Line. Matthew Bender. Friday 18 th September, CMSC Command Line Workshop

Linux Refresher (1) 310/ Fourth Workshop on Distributed Laboratory Instrumentation Systems (30 October - 24 November 2006)

Unix Handouts. Shantanu N Kulkarni

Topic 2: More Shell Skills

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Introduction to Linux Part 2b: basic scripting. Brett Milash and Wim Cardoen CHPC User Services 18 January, 2018

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Working with the Linux Shell

Shell Programming (bash)

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Transcription:

Chapter 9 Linux Shell 1 Shell and Kernel Shell and desktop enviroment provide user interface 2 1

Shell Shell is a Unix term for the interactive user interface with an operating system A shell usually implies an interface with a command syntax User types the command at prompt, and shell convert and execute it, or pass to the kernel 3 Shell functions Shell provides : Interactive user interface Interpret user commands which can be read from standard input device, or from a file. User enviroment Providing a user enviroment, which be configured individually using configuration files Shell programming 4 2

Shell types sh or Bourne Shell The original shell on Unix systems bash or Bourne Again shell The standard shell. Expanded from sh csh or C shell tcsh or TENEX C shell ksh or the Korn shell 5 Shell types The default shell for user account specified in /etc/passwd file echo $SHELL List of valid login shells on the system cat /etc/shells Switch to another shell (ex. sh) and exit $ sh $ exit Change the default shell chsh s /bin/sh Current shell echo $0 6 3

Login shell & non-login shell When a user logs into the system, the user is given a shell, which is knows as a login shell There are many non-login shell When a user starts instance of a shell within the X Window system, that is a nonlogin shell When a start another shell at the shell prompt bash>bash bash> Sub-shell Non-login shell 7 The Interactive User Interface Command syntax Built-in Commands Support Command History Support Command Completion Support editing commands Run multiple command Redirection output and input Command Substitution Special characters 8 4

Command syntax command [options] [arguments] Command : name of program Options : options of program, begin or - - Arguments : filename, directory, string, [ ] : optional, not required Using \ to enter a command in multiple line Using Ctrl_C to stop executing a command 9 Built-in Commands Built-in command are contained within the shell itself. Bash built-in commands: alias, bind, builtin, cd, command, declare, echo, enable, help, let, local, logout, printf, read, shopt, type, typeset, ulimit, unalias 10 5

Support command history All command that you entered at the shell prompt is saved in the ~/.bash_history Select one command from history list by: Using Up Arrow key Using history command $ history $ history a $!! $!N 11 Support Command Completion a helpful feature when you need to enter a very long file name in a command line Press TAB key while entering a command tar zxvf /software/units-1.74.tar.gz Press TAB Press TAB 12 6

Support editing commands Bash shell allows to edit commands you type at the shell prompt, using Readline Library editor 13 Run multiple command in command line command1 ; command2 ; command3 ; [commandn] $ who ; date ; echo $SHELL ; ls / Commands be executed in succession 14 7

Input - Output Redirection There are three file descriptor for every command stdin (0) : is the input provided to a particular command to process stdout (1) : is the output from a particular command stderr (2) : is the error code generated by command 15 Input - Output Redirection Default, stdin is the input that read from the keyboard, stdout (stderr) is the output that send to the screen. cat./vd.txt In Linux, It s possible to send output to file or to read input from file, with 3 redirection symbols >, >>, < 16 8

Input - Output Redirection Redirecting output : command output>file_or_device tail /var/log/messages 1>lastmessage.txt tail /var/log/messages >lastmessage.txt cat./file0.txt cat./file0.txt cat./file0.txt 2>errorfile.txt 1>readme.txt 2>errorfile.txt 1>readme.txt 2>&1 cat./file1.txt >> readme.txt 17 Input - Output Redirection Redirecting Input : command <input_file sort sort <./inputfile or sort inputfile sort <./inputfile >./outputfile stdin inputfile sort stdout outputfile ls?? 18 9

Pipe A pipe is a way to connect the output of one command to the input of another command without any temporary file command1 command2 ls more ls sort ls wc l ls grep vd who sort who wc l cat /var/log/messages grep dev more 19 Command Substitution Allows the output of one command to be used as arguments to another ls l ` find./ -name vd* ` or ls l $( find./ -name vd* ) 20 10

Special Characters Include \ ( ; # $? & * ( ) [] ` + These characters have a special meaning or function If they are used in way that not have special meaning, must be use with \ (back-slash) echo ` find./ -name vd* ` echo \` find./ -name vd* \` echo $PS1 echo $PS1 //double quotes //forward tics : remove the special meaning of a character or string 21 Manage User Enviroment Setting up user enviroment by runing configuration files and set enviroment variables Manage Enviroment Variables 22 11

Configuration files Script files that get run at login, or logout Includes /etc/profile, ~/.bashrc, ~/.profile (on SuSe) ~/.bash_profile and ~/.bash_logout (on Fedora) The login shell reads these file the following in order : /etc/profile => ~/.profile (on SuSe) /etc/profile => ~/.bash_profile (on Fedora) /etc/profile file contains configuration parameters that applied all users (system-wide). ~/.profile file contains configuration parameters that applied a user itself The nonlogin shell reads ~/.bashrc /etc/bash.bashrc 23 Manage Enviroment Variables Enviroment Variables are used to define critical parameters for the shell run properly. Enviroment variables are frequently accessed and used by programs cd command check the value of $HOME when it runs 24 12

25 Manage Enviroment Variables Viewing a / all variable echo $PATH env more set more Setting the value of a variable variable=value PATH=$PATH:/var/opt/mydb Most of the value of ev assigned by the system There are many ev that you should not change 26 13

Manage Enviroment Variables Using export command to apply the new value of the variable to all shells in a sessions (including any subshells) PATH=$PATH:/var/opt/mydb echo $PATH export PATH 27 Manage Enviroment Variables To make persistence of the new value of the variable across system restarts, you need to edit one of bash configuration files. 28 14

Make a shell scripts cat myscript #!/bin/bash #a simple script echo hello exit 0 Shell scripts 29 Shell scripts Run a shell scripts : two ways $ bash myscript $ bash./myscript $ chmod 755 myscript $./myscript 30 15

script1 #!/bin/bash echo bạn muốn thêm ñường dẫn nào vào biến PATH? read NEWPATH echo thêm ñường dẫn $NEWPATH vào biến PATH PATH=$PATH:$NEWPATH export PATH echo biến môi trường hiện tại là echo $PATH exit 0 31 Script2 #!/bin/bash echo nhap so thu nhat read NUM1 echo nhap so thu hai read NUM2 SUM=$NUM1+$NUM2 echo tong hai so la $SUM exit 0 #!/bin/bash declare -i NUM1 declare -i NUM2 declare -i SUM echo nhap so thu nhat read NUM1 echo nhap so thu hai read NUM2 SUM=$NUM1+$NUM2 echo tong hai so la $SUM exit 0 32 16

33 17