linux bash it, and what Bourne Again Shell
bash it, and what Bourne Again Shell
Head to write
#! / Bin / bash
set -x #open script debug
1 * Add execute permissions
chmod + x script name
chmod + x testsh1.sh
* 2 executes the script
of the current path of execution
./ script name
testsh1.sh
Full execution path
/tmp/vskedtest/testsh1.sh
Executed by an interpreter
/ bin / sh script path
/ bin / sh testsh1.sh
/ bin / sh /tmp/vskedtest/testsh1.sh
3 * traverse directory file
shpfilepath = `ls / tmp / vskedtest / *. Shp` # -defined directory traversal
for shpFile in $shpfilepath
do
echo $shpFile
done
4 * Executes the specified script
source script path
5 * for cycle value
for J in $ (SEQ. 1. 3)
do
echo $ J # 2. 3. 1
DONE
Quickly generate sample documents
for J in $ (10 SEQ. 1)
do
echo $ J> $ j.xml
DONE
6 *变量self增1
1 i = `expr $ i + 1`;
2 the let i + = 1;
3 ((i ++));
4 i = $ [$ i + 1];
5 i = $ (($ i + 1))
* 7 receives the incoming parameter
$ 0 is performing path itself
$ 1 the first parameter
$ 2 second parameter
8 * delay
sleep in seconds
sleep 1
9 * to enable or disable script debugging
turned on
set -x
closed
set + x
need to write to #! At / bin / bash line or
/ bin / sh -x xxxx.sh
10 * execute external commands
pgsql_path = / usr / bin
$ pgsql_path / -s shp2pgsql 3857 -W -C
11 * Get the current time
of the original time
echo $ (date)
formatted output
echo $ (date "+% Y- % m-% d% H:% M:% S")
12 * output
to the console
echo "string or variable"
output to a file cover
echo "abc"> / opt / testfile111
output to a file append mode
echo "abc122" >> / opt / testfile111
13 * Defined Functions
myfun1 function () {
echo 'IS myoupt the this "
echo" parameter1 first parameter INPUT ". 1 $
echo" parameter2 second parameter INPUT "$ 2
}
Function calls
myfun1 hello world
14 * variable definition and use
myname="vsked"
echo ${myname}
15* while循环
while condition
do
command
done
Finite loop
int. 1 =
the while ((int $ <=. 5))
do
echo $ int
the let "int ++"
DONE
infinite loop
int. 1 =
the while:
do
echo $ int
the let "int ++"
DONE
Example
interval=6
while :
do
echo "666"
sleep $interval
echo "here is 666"
sleep $interval
echo "good idea"
done
16 * execute system commands (note the anti-quotation marks!)
SourceFolderom = "/ opt / testsh / OM /"
for omFile in `ls $sourceFolderom`
do
echo $omFile
done
bash it, and what Bourne Again Shell
Head to write
#! / Bin / bash
set -x #open script debug
1 * Add execute permissions
chmod + x script name
chmod + x testsh1.sh
* 2 executes the script
of the current path of execution
./ script name
testsh1.sh
Full execution path
/tmp/vskedtest/testsh1.sh
Executed by an interpreter
/ bin / sh script path
/ bin / sh testsh1.sh
/ bin / sh /tmp/vskedtest/testsh1.sh
3 * traverse directory file
shpfilepath = `ls / tmp / vskedtest / *. Shp` # -defined directory traversal
for shpFile in $shpfilepath
do
echo $shpFile
done
4 * Executes the specified script
source script path
5 * for cycle value
for J in $ (SEQ. 1. 3)
do
echo $ J # 2. 3. 1
DONE
Quickly generate sample documents
for J in $ (10 SEQ. 1)
do
echo $ J> $ j.xml
DONE
6 *变量self增1
1 i = `expr $ i + 1`;
2 the let i + = 1;
3 ((i ++));
4 i = $ [$ i + 1];
5 i = $ (($ i + 1))
* 7 receives the incoming parameter
$ 0 is performing path itself
$ 1 the first parameter
$ 2 second parameter
8 * delay
sleep in seconds
sleep 1
9 * to enable or disable script debugging
turned on
set -x
closed
set + x
need to write to #! At / bin / bash line or
/ bin / sh -x xxxx.sh
10 * execute external commands
pgsql_path = / usr / bin
$ pgsql_path / -s shp2pgsql 3857 -W -C
11 * Get the current time
of the original time
echo $ (date)
formatted output
echo $ (date "+% Y- % m-% d% H:% M:% S")
12 * output
to the console
echo "string or variable"
output to a file cover
echo "abc"> / opt / testfile111
output to a file append mode
echo "abc122" >> / opt / testfile111
13 * Defined Functions
myfun1 function () {
echo 'IS myoupt the this "
echo" parameter1 first parameter INPUT ". 1 $
echo" parameter2 second parameter INPUT "$ 2
}
Function calls
myfun1 hello world
14 * variable definition and use
myname="vsked"
echo ${myname}
15* while循环
while condition
do
command
done
Finite loop
int. 1 =
the while ((int $ <=. 5))
do
echo $ int
the let "int ++"
DONE
infinite loop
int. 1 =
the while:
do
echo $ int
the let "int ++"
DONE
Example
interval=6
while :
do
echo "666"
sleep $interval
echo "here is 666"
sleep $interval
echo "good idea"
done
16 * execute system commands (note the anti-quotation marks!)
SourceFolderom = "/ opt / testsh / OM /"
for omFile in `ls $sourceFolderom`
do
echo $omFile
done