Shell exercise: svndiff & change_ip

Source: Internet
Author: User

Write in ShellCodeSome commands are commonly used, so we can integrate them to implement some small functions. Take a note:

The first script is used to compare different versions of SVN, with the help of SVN's command line tool and vimdiff tool:

 

 

Code

  
# ! /Bin/sh
# Filename = date + % Y % m % d % H % m % s
Filename = $ { 1 # #*/}
If [ " $ # " = 2 ]; Then
SVN up $ {1}
CP $ {1} " /Tmp/$ filename " '. Right'
SVN up - R $ {2} $ {1}
CP $ {1} " /Tmp/$ filename " '.' " $2 "
CP " /Tmp/$ filename " '. Right' $ {1}
Vimdiff / TMP / $ {Filename} . $ {2} / TMP / $ {Filename} . Now
Exit 0
Elif [ " $ # " = 3 ]; Then
CP $ {1} " /Tmp/$ filename " '. Right'
SVN up - R $ {2} $ {1}
CP $ {1} " /Tmp/$ filename " '.' " $2 "
SVN up - R $ {3} $ {1}
CP $ {1} " /Tmp/$ filename " '.' " $3 "
CP " /Tmp/$1 " '. Right' $ {1}
Vimdiff / TMP / $ {Filename} . $ {2} / TMP / $ {Filename} . $ {3}
Exit 0
Fi
Echo " ========================================================== === "
Echo " Format: svndiff file Version1 [version2] "
Echo " Eg: svndiff ZYF. php 1923 1099 "
Echo " Example: svndiff ZYF. php 1923 "
Echo " ========================================================== === "

 

 

 

Well, this script supports two command formats:
Svndiff ZYF. php 1923 1099 # This compares r1923 and r1099 in SVN
Svndiff ZYF. php 1923 # This compares r1923 In the svn library with the latest version.

The second script is used to change the Domain Name Pointing to the IP address and perform some tests on the Intranet:

 

Code

  
# ! /Bin/sh
If [ " $1 " = " 163 " ]; Then
Echo " 163 go! "
Elif [ " $1 " = " 162 " ]; Then
Echo " 162 go! "
Elif [ " $1 " = " 0 " ]; Then
Echo " OK "
Else
Printf " Usage: {163 | 162 | 0 | test1} \ n "
Fi

Cat " $0 " | Sed - N' / ^ # No/P' | SED's/^ # No // '>/etc/hosts
Cat " $0 " | Sed - N' / ^ # '"$1"'/P' | SED's/^ # '"$1"' // '>/etc/hosts

# Init
# No 127.0.0.1 localhost
# No 127.0.1.1 ZYF-laptop
# No
# No # the following lines are desirable for IPv6 capable hosts
# 1 localhost ip6-localhost ip6-loopback
# No fe00: 0 ip6-localnet
# No ff00: 0 ip6-mcastprefix
# No ff02: 1 ip6-allnodes
# No ff02: 2 ip6-allrouters
# No ff02: 3 ip6-allhosts

# # Quick Switch begin
# # Tip 163 test environment
# 163 192.168.1.163 www.zhangabc.com
# # Quick Switch end

 

Excerpt:

Shell parameter Introduction

Just as the LS command can accept directories and other parameters as its parameters, parameters can also be used in shell programming. Shell has location parameters and internal parameters.
1. location parameters
The parameters provided by the system are called location parameters. The value of the location parameter can be obtained using $ N. N is a number. If it is 1, that is, $1. Similar to the array in C language, Linux will segment the input command string
Label each segment. The label starts from 0. No. 0thProgramName, which indicates the parameter passed to the program from 1. For example, $0 indicates the program name and $1 indicates the first parameter passed to the program.
Push.
2. Internal Parameters
In the above process, $0 is an internal variable, which is mandatory, while $1 is dispensable. There are several internal variables that are the same as $0.
$ # ---- Total number of parameters passed to the program
$?---- When the previous code or shell program exits in the shell, if it Exits normally, 0 is returned, and vice versa.
$ * ---- A string consisting of all parameters passed to the program.
$ N---- Indicates the first parameter, $1 indicates the first parameter, and $2 indicates the second parameter...
$0---- Name of the current program
$ @ ---- Save all parameters in the form of "parameter 1" "parameter 2 "...
$ ---- PID of the Program (process ID)
$! ---- PID of the previous command

It is mainly used to practice the basic syntax of shell scripts. The writing must be very nonstandard. please correct me by experienced predecessors. Thank you first.

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.