UNIX操作系统基础(全).ppt

* * * * * * * * * * 在case语句中,字符串变量是依次逐个匹配各个模式的,因此在前面的先检测,后面的后检测。 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 9.10 出错信息和退出状态 操作系统命令出错: sed -r ‘s/this/that/’ myfile 显示: sed: ERROR: Illegal option – r 退出状态: 1 sed -n ‘s/this/that/’ newfile 显示: sed: ERROR: Cannot open newfile: No such file or directory 退出状态: 2 2. 正则表达式出错和模式不匹配: sed -n ‘s/this/that’ newfile 显示: sed: ERROR: Command garbled: s/this/that 退出状态: 0 sed -n ‘s/this/that/’ newfile 显示: 无 (文件中无this字符串匹配) 退出状态: 0 9.10 出错信息和退出状态 3. 出错信息保存和退出状态检测 特别强调: 命令运行结果放在标准输出上 fd = 1 缺省为荧光屏 出错信息放在标准错误输出上 fd = 2 缺省为荧光屏 9.10 出错信息和退出状态 保存出错信息: sed –n ‘1,$s/abc/xyz/’ file 2 err_log 或: sed –n ‘1,$s/abc/xyz/’ file 2 err_log (这两条命令功能上的区别是什么?) 检测退出状态: ① echo $? ② if [ $? -eq 0 ] 其它间接处理 then 正常处理 else 出错处理 fi 9.10 出错信息和退出状态 9.11 sed应用实例 打印文件内容: p命令 sed -n ‘22, 35p’ file1 打印file1的第22~35行 sed -n ‘/string/p’ file2 打印file2中包含string的行 sed -n ‘9, /^uestc/p’ file3 打印file3中第9行到以uestc开头的行 sed -n ‘/[Cc]hina/p’ file4 打印file4中包含China或china的行 2. 删除文件内容: d命令 sed ‘76d’ file5 删除file5中的第76行 sed ‘9,$d’ file6

文档评论(0)

1亿VIP精品文档

相关文档