Reference: http://www.cnblogs.com/dwdxdy/archive/2012/07/25/2608816.html
Often to the stylistic document for line-by-row processing, in the shell how to obtain each row of data, and then processing the row of data, and finally read the next line of
Share a shell script executed by your own Hadoop,
But for those who write shell scripts, it's not going to work.
People who can't write shell scripts seem to be confused.
If you are interested in learning, you can contact in private. As for
The
Question: How does the shell judge a filename to start with a character ~
Solve:
#var = "cn get the length of me"
#$1:parameter 1 to judge the name of the file
Var=$1
Iscn=false
# ${var:0:2} takes the Var substring from the No. 0 character and
Question: For string output such as ' 1,2,3,4,5 ', separate 1 2 3 4 5
Feature: no spaces in string
Workaround 1:
#!/bin/bash
var= ' 1,2,3,4,5 '
var=${var//,/} #这里是将var中的, replace with space for
element in $var
do
echo $ Element done
if else and greater than, less than, equal to logical expressionIf ...; Then
....
Elif ...; Then
....
Else
....
fi [F "somefile"]: judge whether it is a file
[-X "/bin/ls"]: Determine if/bin/ls exists and has executable permissions
[-N ' $var]:
Write:
The shell script is actually a plain text file (ASCII), and we can edit the file to help us execute multiple instructions at a time, or use some operational and logical judgments to help us achieve certain functions. The same considerations
#!/bin/sh
Echo-n "Welcome to I programming World"
Echo-n "This program is a calculator"
Operator= "+-x/exit"
echo "Please input two digits:"
Read Number1 number2
Select I in $operator
Todo
Case $i in
+)
result=$ (($number 1+ $number 2))
[Zxw@host1 ~]$ nl shscp/dump_backup_my.sh1 #!/bin/bash2 #dump MySQL data once per day, the reserve last 7 days data.3 #zhao Xiaowei4 #2014.08.275 Path=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:~/bin6 Export PATH7 dir=
The sort command sorts multiple rows of data in a behavior unit.For example, there is a text file Test_sort, which has five elements, using the sort command, the five elements can be sorted in dictionary order from small to large.If the sort command
Read two files at the same time, and merge their peers into one line to write to a merged file
Shell script:
#!/bin/bash
#set
-x CD ' dirname ' $ '/. /
inas_script_root= ' pwd '
function Make_if_no_existis_dir ()
{local
dir=$1
if [!-e ' $
Variable setting rules1. Variable names can consist of letters, numbers, and underscores, but cannot begin with numbers;2, in bash, the default type of the variable is a string, if you want to do numeric operations, you must specify the variable
ifMulti-branch statement practice#!/bin/bashread-p " Please enter 100 m running seconds: "IIf [$i-lt] && [$i-GT 0]Thenecho " Enter the final "read-p " enter male and female "aif [$a = male]Thenecho " into the men's group "elif [$a = female]Thenecho "
Shell script:
A text file that contains some commands or declarations and conforms to a certain format
Format requirements: First line shebang mechanism
#!/bin/bash
#!/usr/bin/python
#!/usr/bin/perl
The
Both exec and source belong to the Bash Internal command (builtins commands), where you can view all the internal command information by entering man exec or man source under bash.The bash shell commands are divided into two categories: external
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