variable name are optional, plus the curly braces are used to help the interpreter identify the bounds of the variable , such as the following:
for inch
Do
"I am Good at ${skill}script"
Done
If you do not add curly braces to the skill variable and write the echo "I am good at $skillScript", the interpreter will treat $skillscript as a variable (whose value is null)and the result of the code execution is not what we expect it to look like.It is a good progr
1. Preface
This is a series of learning documents. Based on the spirit of Internet sharing, it mainly comes from the shell area on the Forum. It has been organized and is the content of a book. Therefore, copyright belongs to the original author of the book, here we only use learning materials. In fact, these documents are still very fast to organize. After all
See other people's study summary, feel good turn over (transfer from tryfly)First, Shell Script FoundationThe shell script is a program written using the shell's function, which uses a plain text file, writes some shell syntax and instructions inside, and then uses regular expressions, pipe commands, and redirect functions to achieve what we want to do. Its basic
will return:
lf.gz: gzip compressed data, deflated, original filename,last modified: Mon Aug 27 23:09:18 2001, os: Unix
We use this to write a script named smartzip, which can automatically decompress bzip2, gzip, and zip compressed files:
#!/bin/shftype=`file "$1"`case "$ftype" in"$1: Zip archive"*)unzip "$1" ;;"$1: gzip compressed"*)gunzip "$1" ;;"$1: bzip2 compressed"*)bunzip2 "$1" ;;*) echo "File $1 can not be uncompressed with smartzip";;esac
You may notice that we use a special variable $
Linux shell script basic learning Lecture 3: When we introduced shell commands and Process Control in the previous section, we could not talk about process control due to space limitations, today, we will only introduce the first three parts of if case and select. The following three parts can only be introduced in the fourth lecture of Linux
]; then command; FiSyntax twoIf conditionThenCommand1ElseCommand2FiGrammar ThreeIf conditionThenCommand1Elif conditionThenCommand2ElseCommandFi3. Operators1. Arithmetic operatorsNative bash does not support simple math operations but can be implemented with other commands such as exprInstance:2. Relational operators:3. Logical operators4. String operators5. File test operators (emphasis)Various properties used to detect the Unix/linux fileIncluded opt
Linux Shell programming learning notes log on to Shell, the Shell program automatically loaded after you log on to the system. Most Linux systems use/bin/bash as the shells that can be used by the Shell system supported by the def
Similar to other programming languages, the shell supports A for loop.The general format for A for loop is:For variable in list Docommand1command2...commandndoneA list is a sequence of values (numbers, strings, and so on), each separated by a space. Each time the loop is passed, the next value in the list is assigned to the variable.The in list is optional, if it is not used, the For loop uses the command-line positional parameters.For example, sequen
Shell Programming:Bash:#!/bin/bash must be specified at the beginning of the shellHow the Shell executes:1../1.sh executes the 1.sh,1.sh in the current directory if the executable file2. bash/usr/local/1.shDefine variable aa= ' QQQ ' = cannot have spaces on either side, use variable ${AA}
在的话, continue to executeLogmsg-----------system-info ' uname-a '#判断是redhat或者debian系统cat/etc/redhat-release| | Debug 8 This was not a redhat system!cat/etc/debian-release| | Debug 8 This was not a Debian system!#书上更多点, I omitted some of it here, for brevityRun results[Email protected] shell]#./debugger.shLinux www.centos.vbird 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 00:31:26 UTC x86_64 x86_64 x86_64 gnu/linuxCentOS Release 6.4 (Final)Cat:/etc/debian-relea
BASH Shell script learning Summary. It is easy to determine whether a log file is larger than 2 GB. If it is larger than 2 GB, delete it. I haven't written bash for a long time, so I can't even think of it. So I reviewed it and made a summary of today's learning:
1. Charact
[This is my own study notes, welcome reprint, but please specify the source:http://blog.csdn.net/jesson20121020]
Start learning some shell flow control structures like other high-level languages today
Flow control Statements:1. If statementStatement format:If Condition1 then command1else condition2then command2else Command3fiNOTE: The If statement must be terminated with FI. If there is
Statistics commands sort, WC, uniq
Sortsort [-fbmnrtuk] [file or stdin]-F ignores case-B ignores the front space-m sort by month name-N using pure numeric sorting-R Reverse Sort-U The same data item appears only one item-T delimiter-K to sort by that intervalegcat/etc/passwd | Sort-t ': '-K 1//pair to: Sort the first column of the split
WC statistic Word, line or character numberWC [-LWM]-L Number of rows-W Words-M character CountegCat/etc/profile | Wc-lwm
Uniq duplicate data a
take a look at an example. suppose there are some files in the current directory, two jpg files, mail.jpg and tux.jpg.1.2 compile SHELL scripts# Ch #! /Bin/sh mod + x filenameCho *. jpg is slow. why ?. /Filename to execute your script.This will print the result of "mail.jpg tux.jpg.Quotation marks (single quotation marks and double quotation marks) will prevent such wildcard extension:
#!/bin/shecho "*.jpg"echo '*.jpg'
This will print "*. jpg" twice.
· CMD in the execution of the shell regardless of · What is the content of, advanced interpretation, and then the interpretation of the final results to the shell, if the result of interpretation is not the shell can command, will be error. However, only the execution results of CMD are output as text, there is no problem.Such as:[Email protected] root]# i=0[Emai
includes a knowledge point, the command list of knowledge, a simple extension.Command1 command2 command3 ... This shell statement executes from left to right, and the first command that returns false is no longer executed.Command1 | | Command2 | | Command3 | | ..... This shell statement executes from left to right, and the first command that executes successfully is no longer executed. The For Loop exec
/ETC/BASHRC the environment variable profile for the above three paths is valid for all users ~/.bash_profile ~/.BASHRC profile environment variables for the current user when the environment profile for the above two paths is in effect Flowchart: Logoff Environment Profile: ~/.bash_logout default is empty history command profile: ~/.bash_history Shell Login Information:Post-logon information: Valid for both local and remote:/ETC/MOTD default is empty
script prompts you to enter 1 to 4 to match each pattern:
Echo ' Input a number between 1 to 4 '
echo ' Your number is:\c'
Read Anum
Case $aNum in
1) echo ' you select 1 '
;;
2) echo ' you select 2 '
;;
3) echo ' you select 3 '
;;
4) echo ' you select 4 '
;;
*) echo ' Do not select a number between 1 to 4 '
;;
Esac
Enter different content, there will be different results, for example:Input a number between 1 to 4Your number Is:3you Select 3One more
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.