Linux programming (version 2nd)
Chapter 2 shell program design
1. Execution of another script in a script program is much slower than execution of a function; execution result return is also more difficult; and may cause too many small scripts.
In Linux, the/bin/sh command is usually a link to the shell in the actual application. It is a link to/bin/bash in most Linux systems.
2. on a UNIX system, you can always ensure that there is a basic shell. in fact, without/bin/bash, most Unix systems won't be able to boot, not to mention letting users log on to the computer.
3. in the shell script program, we can execute two types of Command commands, that is, the common commands that can be executed at the command prompt and the "Built-in" commands we mentioned earlier. the "Built-in" command is implemented inside shell and cannot be called as an external program. most commands are part of POSIX technical specifications and are often provided with independent corresponding programs. commands are usually internal or external, but they are more efficient to execute.
Now that we have mentioned the problem of implementing commands, we need to know how UNIX uses a program as several commands or different files. run the "ls-L" command to check the MV, CP, and LN commands. We will find that their implementations on many systems are the same file, just use the ln command to create several different names. when this command is called, he will first check his first parameter-in UNIX, this will be the name of the command itself, and then decide what action to take.
4.: Colon command
This is an empty command, which is occasionally used to simplify logical conditions, equivalent to a real name. because it is built-in, it runs faster than true, but its readability is much worse.
: It can also be used to set conditions for variables, such
:$ {Var: = value}
If there is no ":", shell will try to interpret $ VaR as a command
5. EXEC command
Exec has two different usage methods (1) it is often used to replace the current shell with another different program
(2) The second usage is to modify the descriptor of the current file: exec 3 <afile
Chapter 4 how to use and process files
1. There are three important device files:
(1)/dev/console device
Representative Console
(2)/dev/tty
Special file/dev/tty is a Kana (Logical Device) of a process control terminal (keyboard and display, or keyboard and window)
Note that there is only one/dev/console device, but many physical devices can be accessed through/dev/tty.
(3)/dev/null
Null Device
2. Relationship between file streams and file descriptors
Each file stream is associated with an underlying file descriptor. we can mix the underlying input and output operations with the high-level file stream operations, but in general this is not a wise method, because it will make the consequences of data buffering unpredictable.
# Include <stdio. h>
Int fileno (File * stream );
File * fdopen (INT fileno, const char * mode );
3. Maintain files and subdirectories
Int chmod (const char * path, mode_t mode );
Int chown (const char * path, uid_t owner, gid_t group );
Int mkdir (const char * path, mode_t mode );
Int rmdir (const char * path );
Int chdir (const char * path); // CD command
Int * getcwd (char * Buf, size_t size );
(To be continued)