Linux下的shell编程入门

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

in
1| 2)
::
3| 4)
::
fi elif
else if
5| 6)
::
*}
::
esac
case
|
case
::
case $USER in beichen) Echo You are beichen! ;; liangnian) echo You are liangnian ; // echo Welcome! ;; // root) echo You are root!:echo Welcome! ;; //
?D?D (test)
shell
ifቤተ መጻሕፍቲ ባይዱ
test
shell
(
)
test
shell
shell
1
)
=
!=
-n
-z
2
test
>?
NULL( bash
-eq
-ge
-le
-ne
-gt
-lt
3
!
-a (and)
-o (or)
4
test
-d
-f
-L
-r
-s
-w
-x
file1 ?Cnt(-ot) file2
1
2 ()
[beichen@localhost bin]$ P1 this is a test program // 5 Program name is /home/beichen/bin/P1 // There are totally 5 parameters passed to this program // The last is 0 // The parameters are this is a test program //
$? ----
shell
shell
0
0
$* ----
P1: echo Program name is $0 echo There are totally $# parameters passed to this program echo The last is $? echo The parameters are $*
del #name: del #author: liangnian #this program to compress a file to the dustbin if test $# -eq 0 then
echo Please specify a file! else gzip $1 // mv $1.gz $HOME/dustbin // echo File $1 is deleted ! fi
[beichen@localhost bin]$.f_rmgz /home/beichen/dustbin/nessus-4.0.0.2.tar.gz has been deleted! /home/beichen/dustbin/gftp-2.2.1.tar.gz has been deleted! While
Linux shell
shell
shell
Shell Shell
C Linux
Linux
shell
1
date,
#Program date
#usageto ::show the date in this way ( )
echo Mr.$USER,Today is:
echo date +%B%d%A
echo Whish you a lucky day !
[beichen@localhost /]$ .date
Mr.beichen,Today is:
January 13 Friday
Whish you a lucky day !
date
.
shell
shell
ls
1
1 $1. C
0
0
$1
2
$0
Linux 1
shell
Shell
$N
N
$0
$1
$0
$# ----
2
chmod +x date
ls
[beichen@localhost bin]$ date
Mr.beichen,Today is:
January 13 Friday
Whish you a lucky day !
bin
bin shell .
[beichen@localhost bin]$ PATH=$PATH:$HOME/bin
*) echo Who are you?$USER? ;; esac
[liangnian@localhost bin]$ test
You are liangnian
Welcome!
shell
shell
(
$HOME
/home/beichen, bin
)
date
shell :
[beichen@localhost /]$ bash date
Mr.beichen,Today is:
January 13 Friday
Whish you a lucky day !
Linux
chmod +x date date
shell
for
while
until
for
for
in
do
done
for
.gz #delete all file with extension of gz in the dustbin for I in $HOME/dustbin/*.gz do rm ?Cf $i echo $i has been deleted! done
while do
done while
until until
do
do done
done
do done
:
#test until
#add from 1 to 100
total=0
num=0
until test num ?Ceq 100
do
total=`expr $total + $num` //
,
num=`expr $num+1`
done
echo The result is $total
[beichen@localhost bin]$until
The result is 5050!
Shell If
if
1 then
if
case
elif
2 then
elif
3 then
.. else
fi
Linux if
if
elif
Case
case
相关文档
最新文档