Published Book on Amazon
|All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1|
|All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2|
출판된 한글판 도서
|최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)|
|최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)|
Original Book Contents
20.2 Batch Run of Commands via Script
Here we will look at the script tool we use to process multiple commands in batch at once. We will discuss the concept of script, how to write a script, how to execute a script, and so on.
On Linux systems, Shell plays a central role in executing commands. Among the various Shell programs, BASH is specified as the default shell. BASH receives a command entered by the user in the terminal environment, interprets the meaning of the command, processes the command according to the specified method, and returns the processing result to the user.
Then, Shell not only provides the ability to simply process commands entered by the user in a Terminal environmentthe, but also provides ability to create and run programs that perform a series of processing according to the specified rules as the general programming language such as C or Java can do. Using a program written in Shell, it can read various data, can apply various logics to execute desired operations and commands, and can output processing results in various formats.
A tool that provides this programming capability is script. Script is a program written using Shell command and various operation rules provided by Shell.
A script, like a java script, is converted into a computer language and executed when the program is executed. Commands written in the script are passed to the Shell at the time of execution, interpreted and executed by the Shell, and the output is processed through the Shell. In other words, Shell acts as an Interpreter for script.
220.127.116.11 Commands Available in Script
In the script, you can use all usual Shell commands. You can also run several commands at the one time in sequence. It is basically the same as running commands in a Terminal environment.
However, if you can use simple Shell commands only, you can not do complicated things except simply listing commands in order. Scripts need a separate tool in addition to the usual Shell commands in order to handle a variety of tasks, just like a regular program. So Shell provides a variety of programmatic tools to manipulate complex logical operations and data handlings that can be used in scripts.
18.104.22.168 Features of Script
Script is basically a file written in text file format. You can use any text editor to create the file data.
The script file name usually has a file name with an extension as xxxx.sh, but it does not have to be. Even if saved as a file name with no extension, there is no problem in execution.
A script is a program that can be executed like a normal Shell command. In order for the script file to be executed itself, the execute permission must be granted to the script file.