我编写的第一个实用shell脚本(保存命令的manual说明)

sh/bash/dash/ksh/zsh等Shell脚本
回复
shuqin1984
帖子: 24
注册时间: 2009-07-23 15:22

我编写的第一个实用shell脚本(保存命令的manual说明)

#1

帖子 shuqin1984 » 2009-08-11 9:50

注:如果man英文看不了,可以使用 命令名 --help 查看中文简要说明。不过,并不是所有命令都有help说明。

以下是我编写的第一个实用的shell脚本(写得比较简陋,没有参数检测):

# store manuals of listed commands into corresponding files

for arg
do
man "$arg" | cat > $arg.man
done
保存为cmd文件退出。

这是个for循环控制结构,对arg指定的变量(这里是命令)执行 man"$arg" | cat > $arg.man;其中 $ 取变量的值
符号“|” 将man "$arg"的输出作为cat > $arg.man的输入。cat > filename 将把屏幕内容重定向到指定输出文件中去。

你可以这样使用(当然,首先确保要使文件处于工作目录下):
切换到工作目录下: cd 路径名
使用 pwd可以查看你当前的工作目录。

# 先赋予这个脚本执行权限
sudo chmod u+x cmd
#使用
./cmd ls apt-get [command list]
就将ls,apt-get的man文档分别存到 ls.man, apt-get.man中了。


下面保存常用的工具及命令的脚本:

# store manuals of commands listed below into files.
# 赋予权限
sudo chmod u+x cmd

# 保存命令的manual说明
# 先切换到工作目录下,并使cmd在其中(有必要的话,建一个文件夹来保存)

# 软件管理
./cmd apt-get aptitude

# 最常用的实用工具
./cmd ls cat less grep sort head tail uniq diff fc
./cmd history date echo alias tr tee file lpr kill jobs

# 文件定位搜寻
./cmd which whereis apropos locate

# 文件目录操作
./cmd cd pwd cp rm mv dirs mkdir rmdir chmod pushd popd ln

# 压缩相关
./cmd bzip2 bunzip2 bzcat tar zcat gunzip gzip compress

# 显示用户及系统信息
./cmd w who finger hostname

# 通信相关
./cmd mesg write read ping traceroute host dig

# windows与linux文件转换
./cmd unix2dos dos2unix
上次由 shuqin1984 在 2009-08-11 9:59,总共编辑 1 次。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 我编写的第一个实用shell脚本(保存命令的manual说明)

#2

帖子 eexpress » 2009-08-11 9:53

lol
支持折腾
● 鸣学
swows
帖子: 14
注册时间: 2009-07-16 15:53
来自: 北京
联系:

Re: 我编写的第一个实用shell脚本(保存命令的manual说明)

#3

帖子 swows » 2009-08-11 13:37

:em11
Taskcity --> 全球领先的专业软件项目外包平台!
回复