1) Unix command:
Although any Unix command can be used in shell scripts, some more common commands are used. These commands are usually used for file and text operations.
Common command syntax and functions:
Echo"Some text": print the text on
Logical judgments in shell scripts
Format 1:if condition; Then statement; Fi (Common)
#以命令的方式表达[[email protected] ~]# for i in `seq 1 5`; do echo $i; done12345[[email protected] ~]# for i in `seq 1 5`> do> echo $i>
Use the Shell to judge
#!/bin/sh
mypath= "/var/log/httpd/"
myfile= "/var/log/httpd/access.log"
#-x parameter determines whether the $mypath exists and has executable permissions if [!-X "$myPath"]; Then mkdir "$myPath" FI # Here's the-D
Use shell script to monitor whether a process exists without a startup instance, first on the code dry:
#!/bin/sh
ps-fe|grep processstring |grep-v grep
if [$-ne 0]
then
echo "START process ..."
elseecho "runing ..."
fi
Shell basic syntax
Basic shell Syntax:Like advanced programming languages, shell also provides instructions and functions for using variables.For shell, the value of all variables is a string, and the shell program uses $ VaRReference the value
I. Logical judgments in shell scriptsIn the shell script, many will logically judge, judge a certain value, judge a file, or a directory, we do some action against the result of the judgment, if there is no judgment, there is no way to do some
Using a shell to determine whether a device node exists, such as inserting a 4G Modem Sierra module into a Linux system, generates a series of TTY devices, typically with a command to send and receive at. For example, a device node is a/DEV/TTYUSB2
#!/bin/shPs-fe|grep processstring |grep-v grepIf [$?-ne 0]Thenecho "START process ..."Elseecho "Runing ..."Fi#####Processstring represents a process feature string that can be queried for a unique process's characteristic string0 indicates the
Implement code One,
#!/bin/sh # to
determine if a file exists
# link:www.jb51.net
# date:2013/2/28
mypath= '/var/log/httpd/
' myfile= ' Var/log/httpd/access.log "
# Here's the-x parameter to determine if $mypath exists and has executable
1. What is a shell script?It is a scripting language, not a programming language.You can use some logical judgments, loops, and other syntax.You can customize the sub-function, which is a collection of system commands.Shell scripts enable automated
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.