Gets the names of all the folders under the specified directory/usr/and outputs:Shell code:1#!/bin/Bash2 #方法一3 dir=$(ls-l/usr/|awk '/^d/{print $NF}')4 forIinch$dir5 Do6 Echo$i7 Done 8 #######9 #方法二Ten for dir inch$(ls/usr/) One Do A[-D
While loop: Tests a condition repeatedly, as long as the condition is set up and executed repeatedlyThe condition can be: test the expression, or the Boolean value true (the condition is always true) and false (the condition is always false)vi
For i in a B CDoEcho $iDone!ser Historical complements> Correct information output file>> correct information output file, append2> error message output file2>> error message output file append&>> all outputsfree-m | Grep-i Mem | awk ' {print $4,$3}
For loopUsage:forindo 循环体doneSo how do you build the list?{1..100}This will generate the list.===========================================Cases:#!/bin/bash#forin {1..100};do echo$IdoneSeqYou can also generate lists with the SEQ commandUsage:seq
Shell-0. Introduction1. Use shell scripts in those environments• Application environment: Several complex parameters are required to execute certain commandsRequires multiple commands for State view and maintenance management of the systemRegular
First, define variablesWhen defining a variable, the variable name does not have a dollar sign ($), such as:Variablename= "Value"Note that there can be no spaces between the variable name and the equals sign, which may be different from any
1. For loop statements1.1. Syntax Format:For Var in listdo Commandsdonefor ((expression)) do Commandsdone1.2 Simple example:#!/bin/sh# read echo from the direct list "read from direct list" for Var in 1 2 3do echo "$var" Doneecho "\ n"
1 Case-sensitive UNIX is case-sensitive, so shell scripts are case-sensitive 2 special characters Some characters of Unix have special meanings or functions that must be escaped if they are not used in their special sense (escaped). In order to
First, file comparison operators-e filename true if filename exists [-e/var/log/syslog]-D filename True if filename is a directory [-d/tmp/mydir]-F filename True if filename is a regular file [-f/usr/bin/grep]-L filename True if filename is a
A lot of friends do not know how to use shell scripts to collect information about the Linux system, including CPU, memory, disk, network and other information, here the script to do a small part of the explanation, we come together to see it.First,
The content of this section:The awk command implements the concatenation of stringsEnter the contents of the file:Tmall_inventory_30_group my163149.cm6 3506 5683506 mysql-bin. 000013327359057 tmall_inventory_31_group my163149.cm6
Cat/dev/null > FileName Empty file information Trash, the data sent to the secondary file will be deleted. W.H.O. | Wc-l calculating the number of users | (pipeline) can be two more programs between the establishment of a pipeline pipe:who output
write a script to generate a random 3-bit number, and can be based on the user's input parameters to determine the output of a few groups. For example, the script name is number3.sh. Execution Method:Bash 2.shproduces a set of 3-digit numbers
Take a few simple examples of the judgments involved1. Comparison of file-related judgments#!/bin/Bashif[$#-lt1 ] Then Echo "No file name"Exit1elif[-D $1 ] Then Echo$1is directoryelif[-B $1 ] Then Echo$1is block deviceelif[-
Common Options list all files under the directory contain hidden files ls-a list file properties and sort by modified ls-lt list file attributes and sort the file's most recent read time LS-LTU list file attributes and sort files by file size Ls-ls
The common options directory is present without an error (at this time there is no effect on the directory), there is the creation of mkdir-p, if there is a need to create a parent directory when creating a directory when the parent directory is
if ["$test" x = "Test" x]Here are a few key points:1 with a single equals sign, two equals signs can be2 Note that there is a space on each side of the equal sign: This is the UNIX shell requirement3 Notice the last X of "$test" X, which is
Linux shell expr use collectors: Spring and Autumn hundred flavor the-Geneva- +|read: Go:| |share non-original, excerpt from: "Linux and Unix Shell Programming Guide"17.5expr Usage The expr command is generally used for integer values, but can also
/******************************************************************************* * Linux Shell Ls-1 Column Display file * Description: * Sometimes when writing shell scripts, it is often necessary to list the files in a column, and then the * for
The special characters are as follows: "#"--Comment, beginning with # at the beginning of the line (#! is an exception).“;” --the command delimiter, which can be used to write multiple commands on a single line.“;;” --Terminates the "case" option.“.”
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