欢迎来到天天文库
浏览记录
ID:52242192
大小:528.68 KB
页数:10页
时间:2020-03-25
《Linux下的shell编程入门.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、LinuxshellshellshellShellCShellLinuxLinuxshell1date,bin#Programdate#usageto::showthedateinthisway()echoMr.$USER,Todayis:echodate+%B%d%AechoWhishyoualuckyday!2chmod+xdatelsshell.[beichen@localhostbin]$dateMr.beichen,Todayis:January13FridayWhishyoualuckyday!bin[beichen@localhostbin]$PATH=$PATH:$HOM
2、E/bin($HOME/home/beichen,bin)dateshell:[beichen@localhost/]$bashdateMr.beichen,Todayis:January13FridayWhishyoualuckyday!chmod+xdatedateLinux[beichen@localhost/]$.dateMr.beichen,Todayis:January13FridayWhishyoualuckyday!date.shellshelllsshellShell1$NN1$1.CLinux001$0$12$0$1$0$#----$?----shellshell00
3、$*----P1:echoProgramnameis$0echoTherearetotally$#parameterspassedtothisprogramechoThelastis$?echoTheparametersare$*[beichen@localhostbin]$P1thisisatestprogram//5Programnameis/home/beichen/bin/P1//Therearetotally5parameterspassedtothisprogram//Thelastis0//Theparametersarethisisatestprogram//del#na
4、me:del#author:liangnian#thisprogramtocompressafiletothedustbiniftest$#-eq0thenechoPleasespecifyafile!elsegzip$1//mv$1.gz$HOME/dustbin//echoFile$1isdeleted!fitestshell?D?D(test)shellif()testshellshell1NULL(bash)=!=-n-z2test>?-eq-ge-le-ne-gt-lt3!-a(and)-o(or)4test-d-f-L-r-s-w-xfile1?Cnt(-ot)file212
5、()shellforwhileuntilforforindodonefor.gz#deleteallfilewithextensionofgzinthedustbinforIin$HOME/dustbin/*.gzdorm?Cf$iecho$ihasbeendeleted!done[beichen@localhostbin]$.f_rmgz/home/beichen/dustbin/nessus-4.0.0.2.tar.gzhasbeendeleted!/home/beichen/dustbin/gftp-2.2.1.tar.gzhasbeendeleted!Whilewhiledodo
6、newhiledodoneuntiluntildodonedodone:#testuntil#addfrom1to100total=0num=0untiltestnum?Ceq100dototal=`expr$total+$num`//,num=`expr$num+1`doneechoTheresultis$total[beichen@localhostbin]$untilTheresultis5050!ShellifcaseIfif1thenelif2thenelif3then..elsefiLinuxififfielifelseifelifCasecasein1
7、2)::3
8、4)::
9、5
10、6)::*}::esaccase
11、case::case$USERinbeichen)EchoYouarebeichen!;;liangnian)echoYouareliangnian;//echoWelcome!;;//root)echoYouareroot!:echoWelcome!;;//*)echoWhoareyou?$USER?;;esac[liangnian@localhostbin]$testYouareliangn
此文档下载收益归作者所有