UNIX Shell编程.ppt

上传人:asd****56 文档编号:87328135 上传时间:2023-04-16 格式:PPT 页数:70 大小:305KB
返回 下载 相关 举报
UNIX Shell编程.ppt_第1页
第1页 / 共70页
UNIX Shell编程.ppt_第2页
第2页 / 共70页
点击查看更多>>
资源描述

《UNIX Shell编程.ppt》由会员分享,可在线阅读,更多相关《UNIX Shell编程.ppt(70页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、 2010 Hewlett-Packard Development Company,L.P.The information contained herein is subject to change without notice UNIX Shell-Scripting BasicsAgendalWhat is a shell?A shell script?lIntroduction to bashlRunning CommandslApplied Shell ProgrammingWhat is a shell?%What is a shell?/bin/bashWhat is a shel

2、l?#!/bin/bashWhat is a shell?INPUTshellOUTPUTERRORWhat is a shell?lAny ProgramlBut there are a few popular shellsBourne Shellsl/bin/shl/bin/bash“Bourne-Again Shell”Steve BourneOther Common ShellslC Shell(/bin/csh)lTurbo C Shell(/bin/tcsh)lKorn Shell(/bin/ksh)An aside:What do I mean by/bin?lC Shell(/

3、bin/csh)lTurbo C Shell(/bin/tcsh)lKorn Shell(/bin/ksh)An aside:What do I mean by/bin?l/bin,/usr/bin,/usr/local/binl/sbin,/usr/sbin,/usr/local/sbinl/tmpl/devl/home/borwicjhWhat is a Shell Script?lA Text FilelWith InstructionslExecutableWhat is a Shell Script?%cat hello.sh%cat hello.shhello.sh MY_PROG

4、RAM /tmp/myfilelcat /tmp/myfilelcat 2/tmp/myerrlcat /tmp/myinputlcat /tmp/x 2&1INPUTenvOUTPUTERROR012What is a Shell Script?How To Run%cat hello.sh hello.sh hello.sh hello.sh test.sh _TEST_exit 3_TEST_%chmod+x test.sh%./test.sh%echo$?3Logic:test%test 1-lt 10%echo$?0%test 1=10%echo$?1Logic:testltestl

5、 1 lt 10 l “this string”=“this”l()(1 10)Logic:testl-f/etc/passwd l!f/etc/passwd l-f/etc/passwd a f/etc/shadow l-f/etc/passwd o f/etc/shadow An aside:$()for Math%echo$(1+2)3%echo$(2*3)6%echo$(1/3)0Logic:ifif somethingthen :#“elif”a contraction of“else if”:elif something-elsethen :elsethen :fiLogic:if

6、if$USER eq“borwicjh”then :#“elif”a contraction of“else if”:elif ls/etc/oratabthen :elsethen :fiLogic:if#see if a file existsif -e/etc/passwd then echo“/etc/passwd exists”else echo“/etc/passwd not found!”fiLogic:forfor i in 1 2 3do echo$idoneLogic:forfor i in/*do echo“Listing$i:”ls-l$i readdoneLogic:

7、forfor i in/*do echo“Listing$i:”ls-l$i readdoneLogic:forfor i in/*do echo“Listing$i:”ls-l$i readdoneLogic:C-style forfor(expr1 ;expr2 ;expr3 )do listdoneLogic:C-style forLIMIT=10for(a=1 ;a/path/to/my/passwords _PW_FTP_USER=“sct”_PW_%echo$FTP_USER%./path/to/my/passwords%echo$FTP_USERsct%Variable Mani

8、pulation%FILEPATH=/path/to/my/output.lis%echo$FILEPATH/path/to/my/output.lis%echo$FILEPATH%.lis/path/to/my/output%echo$FILEPATH#*/path/to/my/output.lis%echo$FILEPATH#*/output.lisIt takes a long time to become a bash guru 2010 Hewlett-Packard Development Company,L.P.The information contained herein i

9、s subject to change without notice Running ProgramsReasons for Running ProgramslCheck Return Code$?lGet Job OutputOUTPUT=echo“Hello”OUTPUT=$(echo“Hello”)lSend Output SomewhereRedirection:PipesPipeslLots of Little Toolsecho“Hello”|wc-cINPUTechoOUTPUTERROR012INPUTwcOUTPUTERROR012A Pipe!Email Notificat

10、ion%echo“Message”|mail s“Heres your message”borwicjhwfu.eduDates%DATESTRING=date+%Y%m%d%echo$DATESTRING20060125%man dateFTP the Hard Wayftp n u server.wfu.edu outfilesqlplusJOB=“ZZZTEST”PARAMS=“ZZZTEST_PARAMS”PARAMS_USER=“BORWICJH”sqlplus$BANNER_USER/$BANNER_PW test.sh _TEST_echo“Your name is$1$2”_T

11、EST_%chmod+x test.sh%./test.sh John Borwick ignore-thisYour name is John BorwickScheduling Jobs%crontab-l0 0*daily-midnight-job.sh0*hourly-job.sh*every-minute.sh0 1*0 1AM-on-sunday.sh%EDITOR=vi crontab e%man 5 crontabOther Questions?lShells and Shell ScriptslbashlRunning Commandslbash and Banner in Practice

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 其他杂项

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁