1. The first line of the program specifies the program that executes the shell
#!/bin/sh
#! is used to tell the system that the parameter behind it is the program used to execute the file
2. Output information in the console
echo "Hello Shell"
#!/bin/sh#向控制台输出信息 echo"Hello Shell"
Save, quit!
3, make script executable, need to execute the following command in DOS window
chmod +x FileName
4. Execute script
./helloshell
5, the use of variables
In the shell, variables are not declared and can be used directly (similar to LUA)
Remove variables using dollar sign $
#变量的使用a="I am a variable"echo $aecho ${a}
The curly braces are used to prevent variables from being adjacent to the string, and what is the indeterminate variable! such as: $numth and ${num}th The former variable named numth variable, the latter takes the variable named Num.
6. Shell Common Commands
File Statistics Command: wc–l filename, wc-w filename, wc-c filename: Calculates the number of file lines, calculates the number of words in the file, calculates the number of characters in the file
File copy: CP sourcefile DestFile
Renaming files or moving files: MV oldname newname
Delete Files: RM file
Search string in file (regular expression supported): grep ' str ' fileName outputs the rows that are searched to the console
Output file contents to screen: Cat FileName
Shell Learning notes-the first day