<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Contributed Scripts</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Advanced Bash-Scripting Guide"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Bibliography"
HREF="biblio.html"><LINK
REL="NEXT"
TITLE="Reference Cards"
HREF="refcards.html"></HEAD
><BODY
CLASS="APPENDIX"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Advanced Bash-Scripting Guide: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="biblio.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="refcards.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="APPENDIX"
><H1
><A
NAME="CONTRIBUTED-SCRIPTS"
></A
>Appendix A. Contributed Scripts</H1
><P
>These scripts, while not fitting into the text of this document, do
illustrate some interesting shell programming techniques. They are useful,
too. Have fun analyzing and running them.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="MAILFORMAT"
></A
><P
><B
>Example A-1. <I
CLASS="FIRSTTERM"
>mailformat</I
>: Formatting an e-mail
message</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>#!/bin/bash
# mail-format.sh (ver. 1.1): Format e-mail messages.
# Gets rid of carets, tabs, and also folds excessively long lines.
# =================================================================
# Standard Check for Script Argument(s)
ARGS=1
E_BADARGS=65
E_NOFILE=66
if [ $# -ne $ARGS ] # Correct number of arguments passed to script?
then
echo "Usage: `basename $0` filename"
exit $E_BADARGS
fi
if [ -f "$1" ] # Check if file exists.
then
file_name=$1
else
echo "File \"$1\" does not exist."
exit $E_NOFILE
fi
# =================================================================
MAXWIDTH=70 # Width to fold excessively long lines to.
# ---------------------------------
# A variable can hold a sed script.
sedscript='s/^>//
s/^ *>//
s/^ *//
s/ *//'
# ---------------------------------
# Delete carets and tabs at beginning of lines,
#+ then fold lines to $MAXWIDTH characters.
sed "$sedscript" $1 | fold -s --width=$MAXWIDTH
# -s option to "fold"
#+ breaks lines at whitespace, if possible.
# This script was inspired by an article in a well-known trade journal
#+ extolling a 164K MS Windows utility with similar functionality.
#
# An nice set of text processing utilities and an efficient
#+ scripting language provide an alternative to bloated executables.
exit</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="EXAMPLE"
><A
NAME="RN"
></A
><P
><B
>Example A-2. <I
CLASS="FIRSTTERM"
>rn</I
>: A simple-minded file renaming
utility</B
></P
><P
>This script is a modification of <A
HREF="textproc.html#LOWERCASE"
>Example 16-22</A
>.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>#! /bin/bash
# rn.sh
# Very simpleminded filename "rename" utility (based on "lowercase.sh").
#
# The "ren" utility, by Vladimir Lanin (lanin@csd2.nyu.edu),
#+ does a much better job of this.
ARGS=2
E_BADARGS=85
ONE=1 # For getting singular/plural right (see below).
if [ $# -ne "$ARGS" ]
then
echo "Usage: `basename $0` old-pattern new-pattern"
# As in "rn gif jpg", which renames all gif files in working directory to jpg.
exit $E_BADARGS
fi
number=0 # Keeps track of how many files actually renamed.
for filename in *$1* #Traverse all matching files in directory.
do
if [ -f "$filename" ] # If finds match...
then
fname=`basename $filename` # Strip off path.
n=`echo $fname | sed -e "s/$1/$2/"` # Substitute new for old in filename.
mv $fname $n # Rename.
let "number += 1"
fi
done
if [ "$number" -eq "$ONE" ] # For correct grammar.
then
echo "$number file renamed."
else
echo "$number files renamed."
fi
exit $?
# Exercises:
# ---------
# What types of files will this not work on?
# How can this be fixed?</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="EXAMPLE"
><A
NAME="BLANKRENAME"
></A
><P
><B
>Example A-3. <I
CLASS="FIRSTTERM"
>blank-rename</I
>: Renames filenames containing
blanks</B
></P
><P
>This is an even simpler-minded version of previous script.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>#! /bin/bash
# blank-rename.sh
#
# Substitutes underscores for blanks in all the filenames in a directory.
ONE=1 # For getting singular/plural right (see below).
number=0 # Keeps track of how many files actually renamed.
FOUND=0 # Successful return value.
for filename in * #Traverse all files in directory.
do
echo "$filename" | grep -q " " # Check whether filename
if [ $? -eq $FOUND ] #+ contains space(s).
then
fname=$filename # Yes, this filename needs work.
n=`echo $fname | sed -e "s/ /_/g"` # Substitute underscore for blank.
mv "$fname" "$n" # Do the actual renaming.
let "number += 1"
fi
done
if [ "$number" -eq "$ONE" ] # For correct grammar.
then
echo "$number file renamed."
else
echo "$number files renamed."
fi
exit 0</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="EXAMPLE"
><A
NAME="ENCRYPTEDPW"
></A
><P
><B
>Example A-4. <I
CLASS="FIRSTTERM"
>encryptedpw</I
>: Uploading to an ftp site,
using a locally encrypted password</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>#!/bin/bash
# Example "ex72.sh" modified to use encrypted password.
# Note that this is still rather insecure,
#+ since the decrypted password is sent in the clear.
# Use something like "ssh" if this is a concern.
E_BADARGS=85
if [ -z "$1" ]
then
echo "Usage: `basename $0` filename"
exit $E_BADARGS
fi
Username=bozo # Change to suit.
pword=/home/bozo/secret/password_encrypted.file
# File containing encrypted password.
Filename=`basename $1` # Strips pathname out of file name.
Server="XXX"
Directory="YYY" # Change above to actual server name & directory.
Password=`cruft <$pword` # Decrypt password.
# Uses the author's own "cruft" file encryption package,
#+ based on the classic "onetime pad" algorithm,
#+ and obtainable from:
#+ Primary-site: ftp://ibiblio.org/pub/Linux/utils/file
#+ cruft-0.2.tar.gz [16k]
ftp -n $Server <<End-Of-Session
user $Username $Password
binary
bell
cd $Directory
put $Filename
bye
End-Of-Session
# -n option to "ftp" disables auto-logon.
# Note that "bell" rings 'bell' after each file transfer.
exit 0</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="EXAMPLE"
><A
NAME="COPYCD"
></A
><P
><B
>Example A-5. <I
CLASS="FIRSTTERM"
>copy-cd</I
>: Copying a data CD</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>#!/bin/bash
# copy-cd.sh: copying a data CD
CDROM=/dev/cdrom # CD ROM device
OF=/home/bozo/projects/cdimage.iso # output file
# /xxxx/xxxxxxxx/ Change to suit your system.
BLOCKSIZE=2048
# SPEED=10 # If unspecified, uses max spd.
# DEVICE=/dev/cdrom older version.
DEVICE="1,0,0"
ech
没有合适的资源?快使用搜索试试~ 我知道了~
shell abs英文版
需积分: 10 10 下载量 72 浏览量
2011-10-12
11:06:44
上传
评论
收藏 648KB GZ 举报
温馨提示
共139个文件
html:139个
shell abs 英文版 Advanced Bash-Scripting Guide
资源推荐
资源详情
资源评论
收起资源包目录
shell abs英文版 (139个子文件)
contributed-scripts.html 359KB
xrefindex.html 131KB
system.html 120KB
internal.html 85KB
special-chars.html 85KB
filearchiv.html 68KB
textproc.html 68KB
internalvariables.html 57KB
arrays.html 54KB
index.html 49KB
extmisc.html 44KB
communications.html 40KB
writingscripts.html 39KB
assortedtips.html 34KB
loops1.html 32KB
biblio.html 32KB
bashver4.html 32KB
refcards.html 31KB
colorizing.html 30KB
moreadv.html 29KB
sample-bashrc.html 28KB
part4.html 27KB
parameter-substitution.html 27KB
here-docs.html 27KB
string-manipulation.html 26KB
randomvar.html 25KB
basic.html 25KB
debugging.html 25KB
mathc.html 24KB
gotchas.html 23KB
complexfunct.html 23KB
x16900.html 21KB
testconstructs.html 21KB
ops.html 20KB
x9529.html 20KB
commandsub.html 19KB
dosbatch.html 19KB
othertypesv.html 17KB
sha-bang.html 17KB
timedate.html 17KB
comparison-ops.html 16KB
escapingsection.html 16KB
x22771.html 16KB
testbranch.html 15KB
revisionhistory.html 15KB
procref1.html 14KB
subshells.html 14KB
io-redirection.html 14KB
wrapper.html 13KB
process-sub.html 13KB
localvar.html 13KB
fto.html 13KB
why-shell.html 13KB
devref1.html 13KB
opprecedence.html 13KB
options.html 12KB
zeros.html 11KB
bashver3.html 11KB
varsubn.html 11KB
tabexpansion.html 11KB
declareref.html 11KB
redircb.html 11KB
list-cons.html 11KB
functions.html 10KB
ivr.html 10KB
loopcontrol.html 10KB
localization.html 10KB
quotingvar.html 10KB
credits.html 10KB
exit-status.html 9KB
copyright.html 9KB
unofficialst.html 9KB
bashver2.html 9KB
awk.html 9KB
x17731.html 9KB
exitcodes.html 9KB
globbingref.html 8KB
ioredirintro.html 8KB
x17601.html 8KB
recursionsct.html 7KB
portabilityissues.html 7KB
aliases.html 7KB
recurnolocvar.html 7KB
networkprogramming.html 7KB
systemdirs.html 7KB
terminalccmds.html 7KB
intandnonint.html 7KB
files.html 6KB
scriptanalysis.html 6KB
sysscripts.html 6KB
quoting.html 6KB
securityissues.html 6KB
invoking.html 5KB
standard-options.html 5KB
part5.html 5KB
varassignment.html 5KB
aboutauthor.html 5KB
untyped.html 5KB
optimizations.html 5KB
arithexp.html 5KB
共 139 条
- 1
- 2
资源评论
yjlizic
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Win64OpenSSL-3-3-0.exe
- 课高分程设计-基于C++实现的民航飞行与地图简易管理系统-南京航空航天大学
- 航天器遥测数据故障检测系统python源码+文档说明+数据库(课程设计)
- 北京航空航天大学操作系统课设+ppt+实验报告
- 基于Vue+Echarts实现风力发电机中传感器的数据展示监控可视化系统+源代码+文档说明(高分课程设计)
- 基于单片机的风力发电机转速控制源码
- 基于C++实现的风力发电气动平衡监测系统+源代码+测量数据(高分课程设计)
- 毕业设计- 基于STM32F103C8T6 单片机,物联网技术的太阳能发电装置+源代码+文档说明+架构图+界面截图
- 基于 LSTM(长短期记忆)(即改进的循环神经网络)预测风力发电厂中风力涡轮机产生的功率+源代码+文档说明
- 基于stm32f103+空心杯电机+oled按键+运动算法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功