




已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.0 4.1 Unit 8 Shell Basics Copyright IBM Corporation 2008 Unit Objectives After completing this unit, you should be able to: Use wildcards to access files with similar names Use redirection and pipes to control the input and output of processes Use line continuation to enter commands that span the command line Group commands in order to control their execution Copyright IBM Corporation 2008 The Shell lKorn (ksh) or Bourne (bsh) or C (csh) lUser interface to AIX lCommand interpreter lEnables multiple tasks lComprehensive programming language Copyright IBM Corporation 2008 Metacharacters and Wildcards lMetacharacters are characters that the shell interprets as having a special meaning. Examples: | ; ! * ? $ “ lWildcards are a subset of metacharacters that are used to search for and match file patterns. Examples: * ? ! - Copyright IBM Corporation 2008 / home team01 test1 test1.2 test1.3 myfile ne net new nest few File Name Substitution (1 of 2) Wildcards: *? One character compare: $ ls ne? net new $ rm ?e? few net new Multiple character compare: $ cp n* /tmp ne net new nest $ qprt *w new few $ echo test1* test1 test1.2 test1.3 Copyright IBM Corporation 2008 Inclusive Lists: ! - $ ls nestw net new $ rm fghjdnetw few net new $ ls *1-5 test1 test1.2 test1.3 $ qprt !tn* myfile few $ cat ?!y*2-5 test1.2 test1.3 / home team01 test1 test1.2 test1.3 myfile ne net new nest few File Name Substitution (2 of 2) Copyright IBM Corporation 2008 standard in (0) standard error (2)standard out (1) cmd The Standard Files Copyright IBM Corporation 2008 Standard in:1 Standard error:22 File Descriptors Three descriptors are assigned by the shell when the program starts: Copyright IBM Corporation 2008 Input Redirection lDefault standard input $ mail team01 Subject: Letter This is a letter. Cc: $ lRedirect input from a file: $ ls ls.out $ lRedirecting and appending output to a file: $ who whos.there $ Copyright IBM Corporation 2008 Creating a File with cat lWhile normally used to list the contents of files, using cat with redirection can be used to create a file: $ ls letter acctfile file1 $ cat file1 This is a test file. The file has 2 lines. $ lUsing redirection: $ cat newfile This is line 1 of the file. This is the 2nd line. And the last. $ ls letter acctfile file1 newfile Copyright IBM Corporation 2008 Activity: Review Shell Basics 1 Which files are listed when the following commands are executed? $ ls /home/team01/*.? $ ls /tmp/a-zA-Z*.0-9 2 True or False: The command “ls *“ lists all files in a directory. 3 Write down the file descriptors for the following command: $ wc -l /tmp/lines Standard input: Standard output: Standard error: 4 You want to append file testfile1 to file report99. Which command is correct? ocat report99 report99 ocat testfile1 report99 ocat testfile1 report99 Copyright IBM Corporation 2008 Error Redirection lDefault standard error: $ cat filea fileb This is output from filea. cat: cannot open fileb lRedirecting error output to a file: 2 (To append: 2) $ cat filea fileb 2 errfile This is output from filea $ cat errfile cat: cannot open fileb $ cat filea fileb 2 /dev/null This is output from filea Copyright IBM Corporation 2008 Combined Redirection lCombined redirects: $ command outfile 2 errfile appendfile 2 errfile outfile 2“: $ ls -R outfile ; exit is equivalent to entering: $ ls -R outfile $ exit Copyright IBM Corporation 2008 Line Continuation The backslash () followed by a new line character can be used to continue a command on a separate line. A secondary prompt character “ is issued by the shell to indicate line continuation. $ cat /home/mydir/mysubdir/mydata /home/yourdir/yoursubdir/yourdata Copyright IBM Corporation 2008 Checkpoint (1 of 2) What will the following command match? $ ls ?!a-z*0-9t For questions 2-4, indicate where the standard input, standard output and standard error will go. $ cat file1 standard input (0): standard output (1): standard error (2): $ mail tim newprofile 21 standard input (0): standard output (1): standard error (2): For questions 5, 6, and 7, create command lines to display the content of filea using cat and then perform the following: Place the output of the command in fileb and the errors in filec. Place the output of the command in fileb and associate any errors with the output in fileb. Place the output in fileb and discard any error messages. (Do not display or store error messages.) Copyright IBM Corporation 2008 Checkpoint Solutions (2 of 2) $ cat .profile newprofile 21 standard input (0): keyboard standard output (1): newprofile standard error (2): a file named 1 For questions 5, 6, and 7, create command lines to display the content of filea using cat and then perform the following: Place the output of the command in fileb and the errors in filec. $ cat filea fileb 2 filec Place the output of the command in fileb and associate any errors with the output in fileb. $ cat filea fileb 2&1 Place the output in fileb and discard any error messages. (Do not display or store error messages.) $ cat filea fileb 2 /dev/null Copyright IBM Corporation 2008 Exercise: Shell Basics Copyright IBM Corporation 2008 Unit Summary Wildcards, * and ?, provide a convenient way for specifying multiple files or directory names. The wildcard notation is like using the ? but it allows you to choose specific characters to be matched. Three files automatically opened for redirection are standard in, standard out, and standard error. I/O redirection alters the default input source or output desti
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 文学作品委托创作合同模板4篇
- 2025年重症医学科护理核心制度考试试题及答案
- 材料专业考研试题及答案
- 员工入股协议书样书经典版4篇
- 2025临床康复复试题及答案
- 2025年第一季度三基考核试题及答案
- 体育专业能力试题及答案
- 信息管理专业试题及答案
- 渠道类专业试题及答案
- 电厂灰硫专业试题及答案
- 《建筑设计基础》课件2
- 小学英语冀教版3-6年级单词表
- 产后出血孕期预防策略
- 创新科技项目投资决策的财务效益分析
- 外国运动员体育俱乐部聘用合同
- DL-T 5876-2024 水工沥青混凝土应用酸性骨料技术规范
- 副总经理招聘笔试题与参考答案(某大型国企)2024年
- 挂靠合同协议书版模板
- 【骨肌】化脓性骨髓炎课件
- 部编版五年级上册道德与法治全册课时练(一课一练)(含答案)
- DL∕T 1679-2016 高压直流接地极用煅烧石油焦炭技术条件
评论
0/150
提交评论