1. ENV (environment abbreviation) and export Show all environment variables 2. Description of Environment variables
environment variable
home"
user home folder equivalent to "~"
shell
linux default to/bin/bash
hists " ize
history record number of bars
mail
mail the directory in which messages ar
[This is my own study notes, welcome reprint, but please specify the source:http://blog.csdn.net/jesson20121020]
see how to pass parameters to a shell script today, you need to master two commands, one is the shift command, the other is getopts.
Script parameter Passingshift CommandUsage:Shift n Shifts the parameter position to the left n bits at a timeIf we want to implement the statistics of the total number of files, we can use this shift
often configures a long directory name (to avoid forgetting), But changing the directory is a hassle. At this point, Brother Bird is accustomed to using the following way to reduce the issue of the command issued wrong:
[[email protected] ~]# work= "/cluster/server/work/taiwan_2005/003/"
[[Email protected] ~]# CD $work
future I want to use a different directory as my mode working directory, just change work this variable! And this variable can be directly specified in t
out the last/and left string: my.file.txt${file#*.} Take out the first one. And the string to the left: file.txt${file##*.} Take off the last one. And the string to the left: txt${file%/*} take out the last/And right string:/dir1/dir2/dir3${file%%/*} take out the first/and the right string: (null value)${file%.*} take off the last one. And the string to the right:/dir1/dir2/dir3/my.file${file%%.*} take off the first one. And the string to the right:/dir1/dir2/dir3/myTest.sh:File=dir1/dir2/dir3/
red output Hello world.
2. Define the script:A, create a hello.sh text file;b, and then start with #!/bin/bash, where the declaration of the script must be added.c, output instructions. The # in the instruction indicates the meaning of the comment.Cases:#!/bin/bash#myFirst program! Echo " \e[1;31mhello wolrd\e[0m" 3. Execute scriptA. Execute scripts directly using
To see what versions of the Shell:cat/etc/shells system are currently running, the first process that starts is initHow bash Shell debugs:Simply add parameters after the SH command-N: Do not execute scripts, query the grammar within the scripts, if there are errors are listed!-V: The contents of scripts are displayed on the screen before executing the scripts;-x: The scripts content that will be used is dis
True when string str1 and str2 are not equal-N str1 True when the length of the string is greater than 0 (string non-null)-Z str1 True when the string length is 0 (empty string)STR1 is True when string str1 is not empty2, the number of the judgmentInt1-eq int2 Two numbers equal to TrueInt1-ne Int2 Two number is trueINT1-GT Int2 int1 greater than Int2 is trueInt1-ge Int2 int1 greater than or equal to Int2 trueInt1-lt Int2 int1 Less than Int2 is trueInt1-le Int2 int1 less than or equal to Int2 tr
行脚本参数的个数Echo '$*='$* #所有参数变成一个字符Echo '[Email protected]='[email protected] #所有参数basename$0 #获取文件名dirname$0 #获取文件的目录[email protected] sbin]#SH/usr/local/sbin/test.SHAA bb$0=/usr/local/sbin/test.SH$1=aa$#=2$*=AA Bb[email protected]=AA bbtest.SH/usr/local/sbinProcess state variables$? Gets the return value that executes the last command (0 is successful, others are failed)$$ getting the PID of the current shell$_ gets the last parameter of the previous c
Tags:tty a regular expression devproject passwd regular penwho #!/bin/bash-#echo do what exetuate this project \nprintf "Please input your passwd" Stty-echoread Pass Shell Scripting Learning-2
Parameters:-N does not execute script, only checks syntax for errors-V Output the script contents to the screen and execute the script-X executes the script and outputs the content to the screen-N-VTen module () { eval '/usr/bin/modulecmd bash $*'}#/bin/bashif [$15 ];then "Yes"or "else" No " Fiyes-X[[Email protected] sbin]# SH-'['5']' 2operator expected+ echo NonoExpand:Use PS4 to make debugging output line numbers[[email protected] sbin]#
-decrement is no problem.Echo $ ((--STR))12Echo $ ((--STR))11Echo $ ((++str)) #结果正常12Echo $ ((++STR))13Echo $ ((--STR))12You can also use [].echo $[str= $str +6] #在 [] Use the variable symbol $18Echo $[str=str+6] #[] does not use the $ symbol24However, if $[$str =str+6] or $[$str = $str +6] An error will occur.echo $[$str =str+6]-bash: 24=str+6: Attempted assignment to Non-variable (Error token is "=str+6")echo $[$str = $str +6]-
corresponding child shell. It is also necessary to restart or use the source ~/.bash_profile to make the call to take effect.The read and invoke process for bash is briefly described here:Login Linuxè Read/etc/profile--> read the corresponding user's. bash_profile or. Bash_login or. Profile (priority is reduced from front to back, so there are three kinds of files that are reserved for different Linux tran
"Please input your score:" Aif ((a Thenecho "You didn ' t pass the exam."fi5.1 with the Else instance code is as follows#!/bin/bashread-p "Please input your score:" Aif ((a Thenecho "You didn ' t pass the exam."Elseecho "good! You passed the exam. "fi5.2 with Else if (this is the argument in C) is represented in the shell as Elif#!/bin/bashread-p "Please input your score:" Aif ((a Thenecho "You didn ' t pass the exam."elif ((a>=60)) ((a Thenecho "go
Login Host:
Native Login (7 interface Tty1~tty7)
Text Interface (TTY1~TTY6)
Graphical Interface (TTY7)
Telnet
wildcard characters:
*: Represents an arbitrary string, which can be an empty string
? : Represents a character, but cannot be empty
escape character : \line continuation symbol : \Character Set :
[A-z]: English Small Letter
[A-z]: English capital letters
[A-za-z]: English case letters
[0-9]: Number
[a-z
Tags: learning recordMeaningless script, big God do not spray/[[emailprotected]desktop]#vimoraclesh.sh #!/bin/bash Clear #函数 test_parameter1 () {' echo ' su-oracle-c ' sqlplus/nolog ' This article is from the "One Meter Sunshine" blog, please be sure to keep this source http://sunshine3.blog.51cto.com/3988340/1703840A little bit of learning
cycleFormatUntil commandDoStatement (s) to being executed until command is trueDoneExit Loop: Break, continueNote:(1) in a nested loop, break n means exiting the nth layer loop and counting from the inner layer.(2) Continue exits the current loop.Nine,shell function
Delete function: $unset. f function_name
When n>10 need ${n} to obtain parameters, n
X. input/Output redirection(1) > (or (2) >> (or Xi.Shell file containsThe
function.
Like what:
1 #!/bin/bash
2 hello () {
3 echo "My name is Xu Hao"
4}
5
6 #调用上面的函数
7 Hello
Run Result:
root@iz28t5k4ny4z:/usr/xiho/shell#./06.sh my
name is Xu Hao
calling a function requires only the name of the function and does not require parentheses.
Let's look at a function with the return statement:
After t
Shell learning-awk getting started
I. awk application scenarios
Format data or extract records from a large text file
Ii. Usage
Command Line$ Awk [-F field-separator] 'commands' input-file (s)Commands is a real awk command[-F domain delimiter] is optional. If no-F option is available, awk uses space as the Separator by default. If the domain separator is not a space, for example, to browse ": the-F option m
#!/bin/bash############################################################### File Name:/server/scripts/maopaopao.sh# version:v1.0# Author: Cattle Farming# Created time:2017-09-20 19:44:10# Description: Bubble sort# Read Instructions:# 1, read-a shuzu-a indicates that the next input is an array Shuzu is the array name set# 2, ${#. [@]} The number of elements representing the array# 3, ${. [@]} Represents all elements of an array# 4 、.. [A] represents the
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.