Shell Programming Notes

Source: Internet
Author: User

View Catalog

awk ' {if (!system ("test-d")) print $} '

Batch Quick Create user

 for  in user{0.. Ten  Do     useradd $i    echo123456passwd --stdin $i Done

Use the IF statement to determine

#!/bin/bash# file Judgmentif[-E $1]; Then    Echo "File exists"fiif[-R $1]; Then  Echo "readable"fiif[ -W$1]; Then  Echo "writable"fiif[-X $1]; Then  Echo "executeable"fiif[-S $1]; Then  Echo "Have contents"fiif[-D $1]; Then  Echo "Directory"fiif[-F $1]; Then  Echo "file"fiif[-C $1]; Then  Echo "charactor Device"fiif[-B $1]; Then    Echo "Block Device"fi#字符串判断if[ $1="Admin"]; Then    Echo "You are admin"fiif[ $1!="Demon"]; Then    Echo "You is not demon"fiif[-Z $1]; Then    Echo "Zero String"fiif[-N $1]; Then    Echo "Not empty"fi#数字判断ifTest $1-eq4; Then    Echo "$1=4"fiifTest $1-ne4; Then    Echo "$1!=4"fiifTest $1-gt4; Then    Echo "$1>4"fiifTest $1-ge4; Then    Echo "$1>=4"fiifTest $1-lt4; Then    Echo "$1<4"fiifTest $1-le4; Then    Echo "$1<=4"fi#C语言语法if(( $1!='Demon')); Then    Echo "[C]not Demon"elif(( $1>5)); Then    Echo "[c]$1 > 5"fi

Color

Danger="\033[31m"Success="\033[32m"Primary="\033[34m"Warning="\033[33m]"Violet="\033[35m"Info="\033[36m"default="\033[37m"CLS="\033[0m"

Catalog file Statistics

#!/bin/Bashline= ' Tree-i-f |WC-l ' files= ' Tree-i-f |Head-N $ ($line-1)) ' FileCount=0Dircount=0 for file inch$files; Do    if[-D $file]; ThenDircount=`Expr$dirCount +1` ; Echo$file    ElseFileCount=`Expr$fileCount +1`    fi DoneEcho "Dir:"$dirCountEcho "Files:"$fileCount

Shell Programming Notes

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.