专藏理工大学 1945 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY Linux开发基础 Development Foundation on Linux OS 方贤进,Ph.D&Associate Prof. 安徽理工大学计算机科学与工程学院 1
1 安徽理工大学 计算机科学与工程学院 Linux开发基础 Development Foundation on Linux OS 方贤进, Ph.D & Associate Prof
安藏理工大学 ANHUI UNIVERSTTY OF SCIENCE TECHNOLOGY Section 1 Shell programming on Linux OS 3
3 Section 1 Shell programming on Linux OS
安藏理工大学 ANHUI UNIVERSITY OF SCIKNCE TECHNOLOGY 1.1 What is Shell? Shell is a command interpreter; Shell is a programming language,which includes variable,keywords and all kinds of control sentences; The generic Shell on Unix OS is Bourne Shell (for short,sh) There are other kinds of shell,C-shell, Korn Shell,etc. 4
4 1.1 What is Shell? ◼ Shell is a command interpreter; ◼ Shell is a programming language, which includes variable, keywords and all kinds of control sentences; ◼The generic Shell on Unix OS is Bourne Shell (for short, sh). ◼There are other kinds of shell,C-shell, Korn Shell, etc
安藏理工大学 ANHUI UNIVERSTTY OF SCIENCE TECHNOLOGY 1.2 How to create and execute shell script? Create a shell Script using VI editor For example: $vi test Where vi is an editor,test is the file name of shell script. 5
5 1.2 How to create and execute shell script? ◼Create a shell Script using VI editor For example: $vi test Where vi is an editor, test is the file name of shell script
安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY 1.2 How to create and execute shell script? To execute a shell Script 1Using input redirection.Let "sh"read commands from shell script filename.E.g. $sh test 2 Script filename is used as arguments of "sh"command.E.g.: $sh script filename [script arguments] 3 Script file is set as "execute attribute",then it can execute directly $chmod +x test $./test 6
6 1.2 How to create and execute shell script? ◼ To execute a shell Script ① Using input redirection. Let “sh” read commands from shell script filename. E.g. $sh < test ② Script filename is used as arguments of “sh” command. E,g.: $sh script filename [script arguments] ③ Script file is set as “execute attribute”, then it can execute directly $chmod +x test $./test