欢迎来到天天文库
浏览记录
ID:34167592
大小:528.68 KB
页数:10页
时间:2019-03-03
《linux下的shell编程入门》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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=$
2、PATH:$HOME/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$#----
3、$?----shellshell00$*----P1:echoProgramnameis$0echoTherearetotally$#parameterspassedtothisprogramechoThelastis$?echoTheparametersare$*[beichen@localhostbin]$P1thisisatestprogram//5Programnameis/home/beichen/bin/P1//Therearetotally5parameterspassedtothisprogram//Thelastis0//Theparametersar
4、ethisisatestprogram//del#name: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)4tes
5、t-d-f-L-r-s-w-xfile1?Cnt(-ot)file212()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/g
6、ftp-2.2.1.tar.gzhasbeendeleted!Whilewhiledodonewhiledodoneuntiluntildodonedodone:#testuntil#addfrom1to100total=0num=0untiltestnum?Ceq100dototal=`expr$total+$num`//,num=`expr$num+1`doneechoTheresultis$total[beichen@localhostbin]$untilTheresultis5050!ShellifcaseIfif1thenelif2thenelif3then.
7、.elsefiLinuxififfielifelseifelifCasecasein1
8、2)::3
9、4)::5
10、6)::*}::esaccase
11、case::case$USERinbeichen)EchoYouarebeichen!;;liangnian)echoYouareliangnian;//echoWelcome!;;//root)echoYouareroot!:echoWelcome!;;//*)echoWhoareyou?$USER?;;esac[liangnian@localhostbin]$testYouareliangn
此文档下载收益归作者所有