linux shell bash 精彩脚本示例,Linux_Shell_Bash_精彩脚本示例.doc

Linux Shell Bash 精彩脚本示例/content/10/0303/18/155970shtml

这些脚本展示了一些有趣的shell编程技术, 但是它们并不适合放入本文档的文本讲解中. 不过它们还是非常有用, 运行和分析它们都是很有意思的事.

译者: 这里留给那些有能力而且有多余时间的读者来详读, 个人认为翻译这些注释有点画蛇添足.

例子 A-1. mailformat: 格式化一个e-mail消息

1?#!/bin/bash 2?# mail-format.sh (ver. 1.1): Format e-mail messages. 3? 4?# Gets rid of carets, tabs, and also folds excessively long lines. 5? 6?# ================================================================= 7?# Standard Check for Script Argument(s) 8?ARGS=1 9?E_BADARGS=65 10?E_NOFILE=66 11? 12?if [ $# -ne $ARGS ] # Correct number of arguments passed to script? 13?then 14? echo "Usage: `basename $0` filename" 15? exit $E_BADARGS 16?fi 17? 18?if [ -f "$1" ] # Check if file exists. 19?then 20? file_name=$1 21?else 22? echo "File \"$1\" does not exist." 23? exit $E_NOFILE 24?fi 25?# ================================================================= 26? 27?MAXWIDTH=70 # Width to fold excessively long lines to. 28? 29?# 30?# A variable can hold a sed script. 31?sedscript='s/^>// 32?s/^ *>// 33?s/^ *// 34?s/*//' 35?# 36? 37?# Delete carets and tabs at beginning of lines, 38?#+ then fold lines to $MAXWIDTH characters. 39?sed "$sedscript" $1 | fold -s --width=$MAXWIDTH 40? # -s option to "fold" 41? #+ breaks lines at whitespace, if possible. 42? 43? 44?# This script was inspired by an article in a well-known trade journal 45?#+ extolling a 164K MS Windows utility with similar functionality. 46?# 47?# An nice set of text processing utilities and an efficient 48?#+ scripting language provide an alternative to bloated executables. 49? 50?exit 0

例子 A-2. rn: 一个非常简单的文件重命名工具

这个脚本是例子 12-19的一个修改版.

1?#! /bin/bash 2?# 3?# Very simpleminded filename "rename" utility (based on "lowercase.sh"). 4?# 5?# The "ren" utility, by Vladimir Lanin (lanin@), 6?#+ does a much better job of this. 7?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值