10-3shell编程.ppt

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

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

1、Linux Shell编程编程处理用户输入处理用户输入命令行参数处理#!/bin/basha=1for(b=1;b$n),而变量$1则被丢弃,$0这个程序名称没变#!/bin/bashcount=1while-n$1doechoparameter#$count=$1count=$count+1#shiftaparmshiftdone#bashtest.shlinuxidcemclinuxracparameter#1=linuxidcparameter#2=emcparameter#3=linuxparameter#4=rac移动多个参数#!/bin/bashechotheoriginalpar

2、ameter:$*#shift3paramshift3echothenewshiftparameteris:$1#bashtest.shaabbccddeetheoriginalparameter:aabbccddeethenewshiftparameteris:dd一些运行选项选项描述-a实现所有对象-c生成计数-d指定目录-e展开对象-f指定读取数据的文件-h显示命令的帮助信息-i忽略大小写-l生成长格式的输出选项描述-n使用非交互式(批量)模式-o指定一个输出文件来重定向输出-q以quite模式退出-r递归处理目录和文件-s以silent模式执行-v生成verbose模式-x排除和拒绝-

3、y设置所有提问回答为yes#!/bin/bashwhile-n$1docase$1in-a)echothe-aoptionexists;-b)echothe-boptionexists;-c)echothe-coptionexists;*)echothe$1isnotanoption;esacshiftdone#bashtest.sh-a-b-c-d-ethe-aoptionexiststhe-boptionexiststhe-coptionexiststhe-disnotanoptionthe-eisnotanoption#!/bin/bashwhile-n$1docase$1in-a)ec

4、hothe-aoptionexists;-b)echothe-boptionexists;-c)echothe-coptionexists;-)shiftbreak;*)echothe$1isnotanoption;esacshiftdonecount=1forparamin$doechoparameter#$count:$paramcount=$count+1done#bashtest.sh-a-c-f-btestthe-aoptionexiststhe-coptionexiststhe-fisnotanoptionparameter#1:-bparameter#2:test#bashtes

5、t.sh-a-c-f-btestthe-aoptionexiststhe-coptionexiststhe-fisnotanoptionthe-boptionexiststhetestisnotanoption获取用户输入#!/bin/bashecho-npleaseinputyourname:readnameechohello$name,welcometokmust#bashtest.shpleaseinputyourname:sgfhellosgf,welcometokmust#!/bin/bashread-ppleaseinputyourname:nameechohello$name,w

6、elcometokmust#bashtest.shpleaseinputyourname:sgfhellosgf,welcometokmust环境变量REPLY#readhellosgf#echo$REPLYhellosgf#!/bin/bashread-ppleaseinputyourname:echohello$REPLY,welcometokmust#bashtest.shpleaseinputyourname:sgfhellosgf,welcometokmust计时#!/bin/bashifread-t5-ppleaseinputyourname:thenechohello$REPLY

7、,welcometocomebackhereelseechosorry,youaretooslowfi说明:-t5是的输入超过5秒则跳到else的判断结果,-p必须放置在-t的后面,否则报错#bashtest.shpleaseinputyourname:sorry,youaretooslow#!/bin/bashread-n1-pdoyouwanttocontinueY/N?case$REPLYinY|y)echoechofine,continueon.;N|n)echoechoOK,goodbye.;esac-n后面是数字1,表示read命令接收到一个字符就退出,所以输入Y/N后不用回车就马上执行下去了密码输入#!/bin/bashread-s-ppleaseinputyourpassword:echoechoyourpasswordis$REPLY-s选项,使得输入的数据颜色跟背景颜色一致,实现不显示数据的效果read命令读取文件#!/bin/bashcount=1cattest.txt|whilereadlinedoechoLINE$count:$linecount=$count+1done每调用一次read命令,都会去读取一行文本作业练习各种输入输出的各种处理方法

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

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

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

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