shell脚本

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

--ShellShellshellLinuxsellShellshellshellshell12shellwindows.bat()shellshellAshellBshellchmod+xshellproCshell./shellproashellLinuxshellbash(bourneagainshell)shellbash@vip.sina.com--Shellbashbashbourneshellneditkeditemacsvishell#!/bin/bash********#Thisisasampleprograme#Author:esnow#Date:2002-03-10#!/bin/bashbshellchmod+xfilenamecshell./filename@vip.sina.com--Shellshell#A.B.shellC.A1shell=2$@vip.sina.com--Shell#!/bin/bash#a=helloworld#aechoAis:echo$afirstchmod+xfirst./firstAis:helloworldnum=2echothisisthe$numndthisisthe2ndthisistheshellnumndshellnumnum=2@vip.sina.com--Shellechothisisthe${num}ndthisisthe2ndB./shellproABCABC$1$2$3($1=A,$2=B,$3=C)$*$#$0shell[root@]#viparechoechoparecho$1echo$2echo$3echo\$0is$0echoparnumis$#chmod+xpar@vip.sina.com--Shell./parabc[root@]#./parabcechoparabc$0is./parparnumis3shift$#exprshellexportShellshell1)Unix:@vip.sina.com--Shellshellunixechosometext:ls:wc–lfilewc-wfilewc-cfile:cpsourcefiledestfile:mvoldnamenewname:rmfile:grep'pattern'file:grep'searchstring'file.txtcut-bcolnumfile:59cut-b5-9file.txtcatcatfile.txt:filesomefile:readvar:sortfile.txt:file.txt@vip.sina.com--Shelluniq:sortfile.txt|uniqexpr:Example:add2and3expr2+3[root@sunyoreshell_esnow]#expr2+72+7[root@sunyoreshell_esnow]#expr2+79find:find.-namefilename-printtee:()somecommand|teeoutfilebasenamefile:basename/bin/tuxtuxdirnamefile:dirname/bin/tux/binheadfile:head-nnumfilenametailfile:tail–nnumfilenamesed:Sedshelllinuxfocus@vip.sina.com--ShellLinuxFocuscattext.file|sed's/linuxfocus/LinuxFocus/g'newtext.fileawk:awk-Fcatfile.txt|awk-F,'{print$1,$3}'””AdamBor,34,IndiaKerryMiller,22,USAAdamBor,IndiaKerryMillercattemp|awk'{print$1?$3!$4}'Default:spaceisvalue2):,backtick(|)grephellofile.txt|wc-lfile.txt”hello”grepwc@vip.sina.com--Shellfind.-mtime-1-typef-print24-mtime–248#!/bin/bash#Theticksarebackticks(`)notnormalquotes('):tar-zcvflastmod.tar.gz`find.-mtime-1-typef-print`3)ifthen@vip.sina.com--Shellif....;then....elif....;then....else....fi…[]testA==-z-nB-eq-ne-gt-lt-le@vip.sina.com--Shell-geC[-fsomefile][-x/bin/ls]/bin/ls[-n$var]$var[$a=$b]$a$b[-d“$a”][-s“$a”]0[-L“$a”][-r“$a”][-z“$a”]mantest#!/bin/bashif[$SHELL=/bin/bash];thenechoyourloginshellisthebash(bourneagainshell)elseechoyourloginshellisnotbashbut$SHELLfi@vip.sina.com--Shell$SHELLshell/bin/bashC[-f/etc/shadow]&&echoThiscomputerusesshadowpasswors&&/etc/shadow”Thiscomputerusesshadowpasswors”(||)shell#!/bin/bashmailfolder=/var/spool/mail/esnowif[-r$mailfolder];thenechoCanread$mailfolderelseechoCannotread$mailfolder;exit0;fi@vip.sina.com--Shellecho$mailfolderhasmailfrom:grep^From$mailfolder#Notice^means:Fromhead&mailfolderFrom--ifcasecase...in...)dosomethinghere;;esac@vip.sina.comfilefilelf.gz--Shelllf.gz:gzipcompresseddata,deflated,originalfilename,lastmodified:MonAug2723:09:182001,os:Unixsmartzipbzip2,gzipzip#!/bin/bashftype=`file$1`case$ftypein$1:Ziparchive*)unzip$1;;$1:gzipcompressed*)gunzip$1;;$1:bzip2compressed*)bunzip2$1;;*)errorFile$1cannotbeuncompressedwithsmartzip;;esac$1smartziparticles.zip$1articles.zip@vip.sina.com--Shellselectbashselectvarin...;dobreakdone....now$varcanbeused....#!/bin/bashechoWhatisyourfavouriteOS?selectvarinLinuxGnuHurdFreeBSDOther;dobreakdoneechoYouhaveselected$varWhatisyourfavouriteOS?1)Linux2)GnuHurd3)FreeBSD4)Other#?1YouhaveselectedLinux@vip.sina.com--Shellshellloopwhile...;do....donewhile-loopwillrunwhiletheexpressionthatwetestforistrue.break”continue”for-loop()forvarin....;do....doneABC#!/bin/bashforvarinABC;doechovaris$vardone@vip.sina.com--ShellshowrpmRPM#!/bin/bash#listacontentsummaryofanumberofRPMpackages#USAGE:showrpmrpmfile1rpmfile2...#EXAMPLE:showrpm/cdrom/Thizlinux/RPMS/*.rpmforrpmpackagein$*;doif[-r$rpmpackage];thenecho========$rpmpackage=========rpm-qi-p$rpmpackageelseechoERROR:cannotreadfile$rpmpackagefidone$*showrpmopenssh.rpmw3m.rpmwebgrep.rpm$*3openssh.rpm,w3m.rpmandwebgrep.rpm.@vip.sina.com--Shell*txtmail.txdttux.txt#!/bin/bashecho*.txtmail.txdttux.txt()#!/bin/bashecho*.txtecho'*.txt'*.txt#!/bin/bashecho$SHELLecho$SHELL@vip.sina.com--Shellecho'$SHELL'/bin/bash/bin/bash$SHELL——echo*.jpgecho\$SHELL*.jpg$SHELLHeredocumentsheredocumentsheredocumentsechoHeredocumentheredocument@vip.sina.com--Shellheredocumentsvihere#!/bin/bash#wehavelessthan3arguments.Printthehelptext:if[$#-lt3];thencatHELPren--renamesanumberoffilesusingsedregularexpressionsUSAGE:ren'regexp''replacement'files...EXAMPLE:renameall*.HTMfilesin*.html:ren'HTM$''html'*.HTMHELPexit0fiOLD=$1NEW

1 / 36
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功