Shell notes, old boy shell notes
Shell: The shell of the operating system, which is the command interpreter.
Is the interface between the user and the Linux kernel.
It is responsible for interacting with users, analyzing and Executing User input commands, and providing results or error prompts.
A shell is specified when each user account is created. When you use this account to register successfully, it will be executed immediately.
The shell prompt of the root account is.
Shell Type:
Ash: shell that occupies the least resources.
Bash: by default, 40 internal commands are used.
Ksh: a total of 42 Internal commands, fully compatible with commercial version ksh.
Csh: A large linux kernel, written in C language. Tcsh is csh, which points to a shell like/bin/tcsh.
Zsh: one of the largest shell, 84 Internal commands.
View the user-specified shell: cat/etc/passwd.
In the content displayed by the command, each line is the user information. The shell type is specified at the end of the information. For example,/sbin/nologin, which is a false shell, indicates that the user cannot log on;/sbin/bash indicates that the user uses bash after logon.
Modify the method of the shell specified by the user:
Modify shell command: chsh.
Shell variable: Used to customize the user's work environment and save useful information so that the system can know the user's settings.
By function: environment variable and local variable. Local variables are limited to only one session.
View environment variables: set command.
Customize or set the variable value: set variable name = variable value
Shell script: saves a series of commands in a file and can execute these commands at one time.
How to execute the script file:
If you want to set the shell for executing the script file, you can write it like this at the beginning of the script file:
#! /Bin/bash
/Etc/profile: Environment Variable file. All environment variables are set in it. This file will be automatically executed upon user logon.
/Etc/bashrc: bash shell environment variable file, which is automatically executed only when the user logs on to the system using bash shell.
~ /. Bash_profile: user environment variable file, which is executed only when the current user logs on.
~ /. Bashrc: Same as above.
Script command:
Shift: it is used to pass the script parameter value to the next bit.
Loop Control:
For I in 1 2 3
Do
.....
Done
While <discriminant command>
Do
....
Done
Until <discriminant command>
Do
....
Done
Conditional test: test command
Test-e [file name]: Check whether the file name exists;
-X [file name]: Check whether the file is executable;
-F [file name]: Check whether the file exists and is a common file;
-L [file name]: indicates whether the file is a hard-linked file.
-D [file name]: indicates whether the file is a directory;
-Nt: whether the former is newer than the latter. Example: test file1-nt file2
Judge two integers:
-Eq: the two values are equal;
-Ne: the two values are not equal;
-Lt: less;
-Gt: greater;
-Le: less than or equal;
-Ge: greater than or equal;
Judge string:
-Z string: whether the string is null;
-N string: whether it is not null;
=: Equal or not;
! =: Are they not equal;
Shell preset parameters:
$0 the preset parameter value is the script name;
1st parameters are $1, and 2nd parameters are $2 ......
Special parameters:
$ @: Contains all parameter values starting from $1, with spaces separated.
$ #: Number of included parameters.
Note: The shift command can change the value of the preceding Special parameters.