10 Common shell scripts for combat and interview--1

Source: Internet
Author: User

# # #10个实战及面试常用的shell脚本

    • Some considerations before writing the script
      • 1. Start with interpreter:
         #!/bin/bash  pre> 
      • 2. Syntax indentation, using 4 spaces, more attention to the description
      • 3. Naming rules:
          Variable name uppercase local variable lowercase function name Lowercase name shows the actual effect  
      • 4. The default variable is global, and the variable local in the function is specified as a local variable to avoid contaminating other scopes
      • 5. Two commands help debug scripts: Pre>SET-E encountered execution of non 0 O'Clock exit script set-x print execution
      • 6. After writing, test to production
    • 1. Get the native IP address (some need to be modified according to the machine, not all Universal)
       method 1:ifconfig eth0 | grep "inet addr" | awk ' {print $} ' | Awk-f: ' {print $} ' method 2:ifconfig eth0|grep ' inet addr: ' |cut-d:-f2|cut-d ' "-f1method 3:ifconfig eth0|sed-nr ' 2s #^.*addr: (. *) bca.*$#\1#g ' pmethod 4:ifconfig eth0|sed-n '/inet/{s/.*addr://;s/. *//;p} ' method 5:ifconfig Eth0|awk '/ inet addr:/ {print $} ' |awk-f: ' {print $} ' method 6:ip add|awk-f ' [/]+ ' nr==8 {print $} '  

10 common shell scripts for combat and interviewing--1

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.