Shell programming-Day 1

Source: Internet
Author: User
Tags array definition case statement

Is there the same command as NBTSTAT in Linux! View other information through IP: Host Name, Mac, etc.

You can use nmblookup-a ip address.

You can also use nbtscan.

ARP command: ARP iPad. Local or ARP 192.168.1.108 or ARP-A or ARP

VI search string: switch to the command mode, and then type/youstring

#! /Bin/bash-E: Stop the script when the first error occurs.-E.

Cat pai_cache.conf | cut-F 3-D, takes three drops as the separator.

Ls-r DOC/| WC-l

Sudo Mount-T smbfs-O codePage = cp936, username = Tom, password = 123456,-l // 192.168.1.118/bu bu_mnt/

Torn

Recursively count the number of folder files.

Linux common sense:
1. Complies with POSIX development standard specifications, and Unix also partially complies with this standard.
2. Version A. B .C. A indicates that the kernel is greatly upgraded. B indicates that the kernel is greatly modified. C indicates that the kernel is greatly modified. c slightly modifies kernel 2.2.2 2.2.4 2.2.6,
The odd version is the test version, and the even version is the stable version. Therefore, we can see the even version. Currently: version 2.6.

Shell introduction:
1. A program that can drive disk rotation is called a driver or a kernel. The called interface exposed to the kernel is called a system call. API is a function.
2. Footsteps: You can directly run it without compilation.
3. CSH: System:/etc/. Login User :~ /. Login ~ /. Cshrc
Bash: System:/etc/profile User :~ /. Bash_profile. bashrc. bash_login. Profile
Vi vim:. exrc. vimrc
4. Shell programming is only applicable to small tools and is not suitable for large programs. Because every command he runs is a new process. Unlike the C language, it runs in a process.

Shell programming:
1. Step 1 :#! /Bin/bash #! The shell script is interpreted and executed using bash.
2. # Comment out exit 0 exit script $ get the variable name & run shleep 3 History in the background to view your operations
3. Run the Script: 1. chomd + x XX. Sh 2. Bash XX. Sh 3.exe c xx. Sh (the current shell will be exited) 4. Source XX. Sh

4. Miscellaneous commands:
1. Cat <End... end specifies the end character as end for output.
2. Command 2> file: Error redirection. ---- A. Out> a.txt 2> & 1 A. Out> & a.txt A. Out &> A. T
3. C language: Use spfintf () to convert a string to a value, and use atoi () atof () to convert a value to a string ()
4. (): Start a sub-Shell under the current shell to execute the command. (PWD) \ escape to continue [] ls [A-F]. *
Ls a. {txt, out}
5. Variable definition: 1. x = x 2. Declare-r a = 100-I-X... $ {var1} avoid ambiguity
6. Read var1 reads a piece of data from the keyboard man bash
7. Environment variable (uppercase): ostype PWD Lang path home seconds shlvl lineno machtype ps1ps2

Special variable: export a = 123; B = 133 Export B; set as system variable
$ @, $ * Display parameters of all locations $ # number of parameters (except the file name) $ display the PID Number of the current process $? Failed to get the status 0 of the previous command.

8. Reference: single quotes can be used to identify variables. Double quotation marks cannot be used to identify floating signs. Use a character as a command to === var =$ (PWD)
*********
= No space left or right: value = space left or right: Comparison
*******
9. Array definition: ABC [1] = 1 ABC [100] = 099 ...... B = (1 2 3 4 5)
10. Operator number:
$ {# Variable name}: length of the variable value to be tested.
Replacement OPERATOR: $ {variable name:-value} + =?
11. String processing:
Substring: $ {STR: 3: 5}
Delete a string (without deleting the body): $ {STR # matching mode }$ {STR # * cwj }## all % forward from the back.
Replace: $ {str/ABC} All $ {STR // ABC/ABC}
Comparison: Str = str-n "$ Str"-z "$ Str" is not empty.
12. Other operators: these operators are the same as those of C ++. Multiple ** operators are used to evaluate the power. Let declare-I (())
13. BC ==> 1000000*1000000 DC is used to calculate big data.
14. Program Control: Test [] and if must be used together with = left and right spaces (comparison)
* ****************: Note: When you remember to use a string, be sure to use, this avoids many problems.

Comparison expression: expression 1-xx expression 2
-Eq-ne-GT-ge-lt-Le if test "$ X"-EQ "$ Y"; then; echo "XX"; FI

15. File test:-F file existence-r user has read permission-s file size is 0! The logic is not [], and both sides must have spaces, the same as test.
16. Test the set-O environment and some configurations in the system. For example, whether to overwrite a file with the same name. Set-O colobber no/off to enable or disable this option.

Case statement: Double semicolons are used in case statements. ---- QU! I always forget to write esac as the end
Case VaR in; yes | yes) ......; [NN] O) ......; *) ......; esac

17. * Indicates all files in the current directory.
Cwj: "wildcard usage" is everywhere in shell scripts ". Good. Haha
In Shell, if case has an ending symbol. Haha
18. For statement: for VAR in *; do xxxx; done xxxx;
For (I = 0; I <10; I ++); Do xxxx; done xxxx; // echo return echo-N without carriage return, the same line is displayed.

1. If []/test then Elif else Fi // If statement
2. #### % deleted. : 3: 4: truncates 4 numbers starting from 3 subscripts. /ABC // A/A :$ {STR # * Lala} $ {str/a/A }$ {STR: 3: 5}
3. For (I = 0; I <10; I ++) do done for VAR in * do done
4. Case VaR in X) echo; y); c );;*)
Echo "plese inter A Var! "
Read inputvar
Case "$ inputvar" in
"A" | "A") echo "case ";;
"B" *) echo "case B ";;
"C") echo "Case C ";;
*) Echo "other"; // The Last One; can be added
Esac
Found during exercises:

1. When the # sign is used, our wildcard should be prefixed, and when the % sign is used, our wildcard should be back. # * 4 Ky! #4 * Bu Ky! % 4 * Ky! % * 4 Bu Ky!
Str= 01234567
Echo $ {STR: 2: 4}
Echo $ {STR #4 *}
Echo $ {STR % 4 *}

2. A = 100 B = 200 C = (A + B): This is an error. It should be like this: (C = a + B )) or C = $ (a + B ))

3 *********************** we often do this: $ (Year % 4 = 0 & year % 100! = 0 | year % 400 = 0): $ (XXX ))

------------- My examples are available in my resources. Haha

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.