Variable type (pre-defined storage format and length of the data) characterNumericalFloating-point type: 11.23PlasticDate-Time TypeBoer type (True and False)Bash Variable type: (and process-dependent)Environment variablesLocal variables (local variables)Position variable $ $4 $ $ $ The first to fifthShift to remove the topmost parameterShift n rejects n above argumentsSpecial variables$? Status return valueNumber of $# parameters$* parameter list 1[Em
In bash script programming, it is easy to confuse and error in some places.
Today I came across an example, for example:
If ["$ uid"-ne "$ root_uid"]ThenEcho "must be root to run this script"Exit $ e_notrootFi
Just a few lines aboveCode, There are two errors.
1) there is no space between If and. Generate an error.2) There is no space between [and "," And],
[[emailprotected]shell]#catmod_ip_hostname.sh#!/bin/bash#automodify Ipandhostname#bycolinon2015-05-07ip_config= '/etc/sysconfig/network-scripts/ Ifcfg-eth0 ' hostname_config= '/etc/sysconfig/network ' hosts_config= '/etc/hosts ' #定义一个IP主要内容数组a =0# Defines the variable a as an array subscript, dynamically used when calling ip_array[a]ip_array= (IPADDRNATMASKGATEWAYDNS1DNS2) #判断IP是否符合标准规则function judge_ip () { #这里local $1 error, using 2>/dev/null to sc
I. Super tools
Terminals, xterms, and shells shell are a full-featured programming environment. The background knowledge is as follows.DEC launched a small PDP-11, known as mini) and a low price of 10000 $), caused a huge response in the university. For ease of transplantation, in 1969, Ken Thompson began to write the first line of code that became opposite to Unix and MULTICS. Later, Dennis Ritchie designed a new programming language for the new oper
Shell Script ProgrammingFgrep Fast grep quickly retrieves text but does not support regular-regular expressionsProgramming languages: Machine language, assembly language, advanced languages (compile required)Compiler or interpreter: is used to translate a language (usually a high-level language) that humans can recognize into a machine that can recognizeLanguage (i.e. machine language)Static language: Compiled language strongly typed (variable) keywor
1. Automatically detect and install nfs-common,
2. automatically create a directory and mount it
3. check whether any configuration exists in the/etc/fstab file. If no configuration exists, add it. Make sure that automatic mount is enabled at next boot.
Install. Sh script:
#!/bin/bash source ../../common/tool.shnfsClient="nfs-common"nfsServerFolder=10.112.18.158:/opt/sharenfsClientFolder=~/test_nfs_dirhasD
-e filename If filename exists, true-d filename If filename is a directory, true-f filename If filename is a regular file, true-l filename if filename is a symbolic link, True-r filename if filename is readable, true-w filename if filename is writable, true-x filename if filename is executable, true-s filename If file length is not 0, true-h fi Lename True if the file is a soft link filename1-nt filename2 True if the filename1 is newer than filename2. Filename1-ot filename2 If filename1 is older
Combine the alias and read usage methods. The ability to save some scripts that will be deferred, or bare data (strings not extended) into a variable. For later use.$ alias begin= ' read-d "" $ Over, in fact Block1 is also a bare data, a BEGIN ... The end block includes random character text. Can be understood asblock1= "Ls-la", it is only here that the text is not extended by the shell engine. Linux Bash script
The bash script is registered as a service and automatically started upon startup. The chkconfig command is used to update (start or stop) and query the running level information of the system service. Remember that chkconfig does not automatically disable or activate a service immediately, but simply changes the symbolic connection. Syntax: chkconfig [-- add] [-- del] [-- list] [System Service] Or chkconfi
In combination with alias and read usage, you can save some scripts that will be run late, or bare data (strings not being extended) into a variable for later use.$ alias begin= ' read-d "" $ Complete, in fact Block1 is a bare data, a BEGIN ... The end block contains any character text that you can understand asblock1= "Ls-la", but this ensures that the text is not extended by the shell engine.Linux Bash Script
/%pattern}Five, character-case conversions:${var^^}: Converts all lowercase characters in var to uppercase;${var,}: Converts all uppercase characters in var to lowercase;Six, variable Assignment:${var:-value}: Returns value if the var variable is empty or not set, otherwise returns the var variable;${var:=value}: If the var variable is empty or not set, then return value and assign value to the var variable, otherwise return the value of the Var variable;${var:+value}: Returns VALUE if the var v
For more information, see the previous article: OSX: Authorization Database)
Here is a real example of system preferences that can be used:
#!/bin/bash## Set the system Authorization Database rights## allow everyone access to system preferences itself security authorizationdb read system.preferences > /tmp/system.preferences.plist /usr/libexec/PlistBuddy -c "set group powerusers" /tmp/system.preferences.plist sudo security authorizationdb
error data output stream that is not to the display device can be called an error redirect or redirect error. Finally learned a particularly useful operation command, its name "Pipeline" is to let a few commands at the same time, greatly simplifying our operation, the teacher's explanation I also deeply feel the importance of this command. This week the content of the study is not much, just as important, to become a Linux operator, can only practice repeatedly, firmly grasp the relevant knowl
You can get the first passed parameter through $0, that is, the script itself. $1 can get the second parameter, for example:
#! /Bin/bashecho "$0" Echo "$1"
RunProgram
./Test/SH Q
See:
$./Test. Sh Q./test. SHQ
When passing parameters, if it is a string, it can be enclosed in single or double quotation marks, indicating that this is a complete parameter:
./Test. Sh 'this is a Test'
Since double quotation marks are i
Nodejs can also be used to write bash.One, write bash--hello.js#! /usr/local/bin/nodeconsole.log ('Hello');Note: Here is the Hashbang I wrote on the MAC command line to write where node is.That's not working for rabbit brother, that's what Bunny wrote.#! /usr/bin/env nodeSecond, give permissionsudo chmod +x hello.js$./
error data output stream that is not to the display device can be called an error redirect or redirect error. Finally learned a particularly useful operation command, its name "Pipeline" is to let a few commands at the same time, greatly simplifying our operation, the teacher's explanation I also deeply feel the importance of this command. This week the content of the study is not much, just as important, to become a Linux operator, can only practice repeatedly, firmly grasp the relevant knowl
If you host your own blog or no web-based application running on the stack, should have a backup system Keeping data stored in MySQL databases safe. There are several solutions that can help for you, and but nothing beats a simple Bash script I stumbled upon in a blog Post comment. Here are the script in all its beauty:
"If you manage to have your own blog or we
Practice One:Pass three parameters to the script, the first is an integer, the second is an arithmetic operator, the third is an integer, the result of the calculation is displayed, and the two-bit precision is required to be preserved. Shaped like:./calc.sh 5/2#!/bin/bash#program:#练习2个整数进行基本算术运算#history 2016-10-21-14:10Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bashExport PATHResul
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.