Comparison of Shell variables

Source: Internet
Author: User


Two comparison of parameters


[Email protected] shell]# VI test.sh
[email protected] shell]# cat test.sh
#!/bin/bash
if [$1-ge];
Then ECHO-E "\033[41;37m < parameter is not correct, the first number is smaller than the second one, quit this operation! > \033[0m "
Else
echo "Start and End time is: ' Date-d" $ days ago "+%y%m%d"--' date-d ' day Ago "+%y%m%d";
Fi
[Email protected] shell]#./test.sh 1 2
Starting and ending times are: 20141116--20141117
[Email protected] shell]#./test.sh 2 1
< parameter is not correct, the first number is smaller than the second one, quit this operation! >
[Email protected] shell]#./test.sh 2 8
Starting and ending times are: 20141110--20141116
[Email protected] shell]#./test.sh 1 90
Starting and ending times are: 20140820--20141117
[Email protected] shell]#./test.sh 1 100
Starting and ending times are: 20140810--20141117
[Email protected] shell]#./test.sh 1 1
< parameter is not correct, the first number is smaller than the second one, quit this operation! >
[Email protected] shell]#

cleanup.sh
#!/bin/bash
Log_dir=/var/Logroot_uid=0 # Only users with a user ID variable $uid a value of 0 have root privileges.LINES=50 # Default number of rowsE_xcd=66 # exit code values that cannot be entered into the directoryE_notroot=67 # code values that are not exited when the root user is not# must be run as root user, the following is detectedIf [ "$UID" -Ne"$ROOT _uid" ]ThenEcho"Must is root to run this script." Exit$E _notrootFiIf [ -N"$" ]# test whether a command-line argument is provided (that is, the test command-line argument has at least one parameter)ThenLines=$ElseLines=$LINES# Default, if not specified in command line.Fi# Stephane Chazelas suggested that#+ below is a better way to detect command-line arguments,#+ but it's still a bit more advanced for now.## e_wrongargs=65 # is not a numeric parameter (parameter format is not correct) when the exit code## case "$" in# "") lines=50;;# *[!0-9]*) echo "Usage: ' basename $ ' file-to-cleanup"; Exit $E _wrongargs;;# *) lines=$1;# ESAC##* can jump to the "loop" chapter to read the first part to understand the above code meaning.CD $LOG _dirIf [ ' PWD ' != "$LOG _dir" ] # can also be used if ["$PWD"! = "$LOG _dir"] # What if the working directory is not in/var/log?ThenEcho"Can ' t change to $LOG _dir." Exit$E _xcdFi #在操作清空日志文件之前再次检查是否在正确的目录里# you can determine again in the correct directory as follows:## Cd/var/log | | {# echo "Cannot change to necessary directory." >&2# exit $E _xcd;# }Tail-$lines messages> mesg. Temp # Saves the message log file with the last few lines of log information to the temporary file. MV MESG. Temp Messages # then overwrites the messages log file with temporary files # cat/dev/null > Messages#* The above sentence empties the messages log file, This keeps the last few lines as above. Security cat /dev/null > wtmp # ': > Wtmp ' and ' > wtmp ' have The same effect. echo "Logs cleaned up." exit 0

Comparison of Shell variables

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.