脚本
文章平均质量分 72
zhouyanldh
1222222
展开
-
case的使用
#!/bin/bash# Testing ranges of characters.echo; echo "Hit a key, then hit return."read Keypresscase "$Keypress" in [[:lower:]] ) echo "Lowercase letter";; [[:upper:]] ) echo "Uppercase l原创 2012-10-30 14:14:08 · 7627 阅读 · 0 评论 -
有关grep, sed, awk命令的练习题
文件:datafileSteve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500Igor Chevsky:385-375-8395:3567 Pop转载 2012-12-09 16:08:53 · 161969 阅读 · 0 评论 -
linux脚本----trap
#!/bin/bash# Hunting variables with a trap.trap 'echo Variable Listing --- a = $a b = $b' EXIT# EXIT is the name of the signal generated upon exit from a script.## The command specified by th转载 2012-11-23 11:29:46 · 41268 阅读 · 0 评论 -
linux脚本----shell 的 && 和 ||
Shell && 和 ||shell 在执行某个命令的时候,会返回一个返回值,该返回值保存在 shell 变量 $? 中。当 $? == 0时,表示执行成功;当 $? == 1 时,表示执行失败。有时候,下一条命令依赖前一条命令是否执行成功。如:在成功地执行一条命令之后再执行另一条命令,或者在一条命令执行失败后再执行另一条命令等。shell提供了 && 和 || 来实现命令执行控制转载 2012-11-23 10:42:24 · 18873 阅读 · 0 评论 -
linux脚本----数组
不知道 是什么时候写的东西,整理文档时被考古发现,给那些闲着蛋疼之人,一笑而过吧。如果本文中的错误给您带来所有的精神损失,请找保险公司理陪!当然你可以告诉我 (倾诉)数组作为一种特殊的数据结构在任何一种编程语言中都有它的一席之地,当然bash shell也不例外。本文就shell数组来做一个小的总结。在这里只讨论一维数组的情况,关于多维数组(事实上,你得用一维数组的方法来模拟),不涉及转载 2012-11-23 10:49:59 · 18956 阅读 · 0 评论 -
linux脚本----函数的使用
#!/bin/bash# Functions and parametersDEFAULT=default # Default param value.func2 () { if [ -z "$1" ] # Is parameter #1 zero length? the转载 2012-11-22 21:08:57 · 18004 阅读 · 0 评论 -
linux脚本----exec的使用
#!/bin/bashexec echo "Exiting \"$0\"." # Exit from script here.# ----------------------------------# The following lines never execute.echo "This echo will never echo."exit 99转载 2012-11-22 21:02:50 · 16909 阅读 · 0 评论 -
shell脚本-fmt
名称:fmt格式:fmt [-cstu] [-p] [-w] [--help] [--version] [文件名]功能:按照指定格式编排文本文件参数: -c或--crown-margin:每段前两列缩排 -p或-prefix=:仅合并含有指定字符串的列,通常运用在程序语言的注解方面 -s或--split-only:转载 2012-11-22 20:45:29 · 16469 阅读 · 0 评论 -
shell脚本---tr的使用
通过使用tr,您可以非常容易地实现 sed 的许多最基本功能。您可以将 tr 看作为 sed的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符。您也可以用它来除去重复字符。这就是所有 tr所能够做的。 tr用来从标准输入中通过替换或删除操作进行字符转换。tr主要用于删除文件中控制字符或进行字符转换。使用tr时要转换两个字符串:字符串1用于查询,字符串2用转载 2012-11-22 20:37:08 · 14566 阅读 · 0 评论 -
linux脚本-let的使用(ex46.sh)
#!/bin/bashecholet a=11 # Same as 'a=11'let a=a+5 # Equivalent to let "a = a + 5" # (Double quotes and spaces make it more readable.)echo "11 + 5 = $a"转载 2012-11-22 20:14:41 · 12060 阅读 · 0 评论 -
shell脚本--printf的使用(ex47.sh)
#!/bin/bash# printf demodeclare -r PI=3.14159265358979 # Read-only variable, i.e., a constant.declare -r DecimalConstant=31373Message1="Greetings,"Message2="Earthling."echoprintf "Pi to转载 2012-11-22 20:17:58 · 13429 阅读 · 0 评论 -
写logfile (ex41.sh)
#!/bin/bash# Generates a log file in current directory# from the tail end of /var/log/messages.# Note: /var/log/messages must be world readable# if this script invoked by an ordinary user.#原创 2012-10-30 20:32:24 · 54074 阅读 · 0 评论 -
select的使用
#!/bin/bashPS3='Choose your favorite vegetable: ' # Sets the prompt string. # Otherwise it defaults to #? .echoselect vegetable in "beans" "carrots" "potat原创 2012-10-30 14:42:18 · 9207 阅读 · 0 评论 -
shell脚本--建立办公室名录
首先copy一份/etc/passwd如下:jones:*:32713:889:Adrian W. Jones/OSD211/555-0123:/home/jones:/bin/kshdorothy:*:123:30:Dorothy Gale/KNS321/555-0044:/home/dorothy:/bin/bashtoto:*:1027:18:Toto Gale/KNS322/555原创 2013-03-04 22:00:26 · 115986 阅读 · 0 评论