Read script code (1)

Source: Internet
Author: User

#! /Bin/sh
# Shell script functions for the ossec HIDS
# Author: Daniel B. CID <daniel.cid@gmail.com>
# Last modification: Mar 02,200 6

True = "true ";
False = "false ";

##########
# Isfile determine whether a file is used
##########
Isfile ()
{
File = $1
# List files and shield all output
Ls $ {file}>/dev/null 2> & 1
# If the returned value is 0, the file is a file; otherwise, the error code is returned.
If [$? = 0]; then
Echo "$ {true }"
Return 0;
Fi
Echo "$ {false }"
Return 1;
}

Usage:
If [! 'Isfile $ {predef_file} '= "$ {false}"]; then
. $ {Predef_file}
Fi

 

 

#0
Ls $ {file}>/dev/null 2> & 1 explanation:
Ls $ {file} is a command,>/dev/null: stdout output result is redirected to/dev/null, that is, no content is displayed; 2> & 1: stderr Input

The output result is redirected to stdout, that is, to/dev/null.
/Dev/null is a black hole and nothing can be entered. Therefore, it means to block the output. Display both standard output and standard error output

.

#1
Test:
] # Ls; First Command
] # Anaconda-ks.cfg install. log. syslog; first output result
] # Ls>/dev/NULL; second command, no output result
] # Ls fdfdf; Third Command: The fdfdf file does not exist
] # Ls: unable to access fdfdf: No file or directory; third output result
] # Ls fdfdf>/dev/NULL; Fourth command
] # Ls: unable to access fdfdf: No file or directory; fourth output result
] # Ls fdfdf>/dev/null 2> & 1; Fifth command, no output result

Proof>/dev/null 2> & 1 blocks all outputs.

#2../src/init/shared. Sh
This file is contained. Equivalent to # include "./src/init/shared. H"

#3/dev/null and/dev/zero
Copy From http://hi.baidu.com/hackers365/blog/item/1f2fd28f4f8e17ff513d92f1.html

/Dev/null. The nickname is a bottomless pit. You can output any data to it. It can be used without support!
/Dev/zero is an input device. You can use it to initialize files.

/Dev/null ------ it is an empty device, also known as a bit bucket ). Any output written to it will be discarded. If you do not want the message

If the standard output shows or writes files, messages can be redirected to the bucket.
/Dev/Zero ------ the device provides 0 infinitely, and you can use any number you need-the device provides more. It can be used

Write string 0 to the backup or file.
$ If =/dev/Zero of =./test.txt BS = 1 k count = 1
$ LS-l
Total 4
-RW-r -- 1 Oracle DBA 1024 Jul 15 test.txt

Eg,

Find/-name access_log 2>/dev/null

In this way, some error messages will not be displayed.

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.