how to write bash script

Alibabacloud.com offers a wide variety of articles about how to write bash script, easily find your how to write bash script information here online.

Bash Script---variables

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

Bash Script Programming 20 Automatic deployment of glassfishv3

recreateSystemUserAndFolder { hasUser $1 r=$? if [ $r -eq 1 ] thenecho "$1 exits already,remove it..."userdel -r $1 elseecho "$1 doesn't exist,create it..." fi adduser --home /home/$1 --system --shell /bin/bash $1 }#remove user group #then create it againfunction recreateUserGroup { hasUserGroup $1 r=$? if [ $r -eq 1 ] thenecho "$1 exists already, remove it..."delgroup $1 elseecho "$1 doesn't exist, create it.

Bash Script Programming-Part 1

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],

Bash-shell-scripts Advanced Script Configuration IP address

[[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

"BASH" proactively cleans up Rman script backup files

************************************************************************* * * * Original:blog.csdn.net/clark_xu Xu Changliang's Column************************************************************************Rman Backup Script#! /bin/bashSu-oracle Rman Target/Backup as compressed BACKUPSET DatabaseInclude current controlfile format '/orabak/db_%d_%t_%s 'plus archivelog format '/orabak/arch_%d_%t_%s ' Delete allinput;Delete NoPrompt obsolete;ExitEof

Script Programming of BASH Shell (1)

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

Bash script programming variables, variable types

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

Bash Script Programming 17 automatic deployment of NFS client

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

./yy.sh-d the arguments that are added when the bash executes the script

-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

Linux Bash script: Define your own delay code block (bare data saving scheme)

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. Details about the chkconfig command

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

Linux Bash Script: Custom delay code block (bare data save scheme)

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

Shell Script Programming Overview (IV): Bash built-in character processing tool

/%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

OSX: utility script (bash scripts) series-23-edit Authentication database

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

Continue to write Vim editor features and bash features

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

Bash Script Programming four external parameters IFS

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 Write Bash

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$./

Continue to write Vim editor features and bash features

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

To back up your MySQL database bash script

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

Linux command exercise: Basic Bash script exercises to take three number of maximum and minimum values

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

Total Pages: 15 1 .... 8 9 10 11 12 .... 15 Go to: Go

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.