Linux脚本编写基础(五)
实例)
现在我们来讨论编写一个脚本的一般步骤。任何优秀的脚本都应该具有帮助和输入参数。并且写一个伪脚本(framework.sh),该脚本包含了大多数脚本都需要的框架结构,是一个非常不错的主意。这时候,在写一个新的脚本时我们只需要执行一下copy命令:
cp framework.sh myscript
然后再插入自己的函数。
让我们再看两个例子:
二进制到十进制的转换
脚本b2d 将二进制数 (比如 1101) 转换为相应的十进制数。这也是一个用expr命令进行数学运算的例子:
1
#!/bin/sh
2
# vim: set sw=4 ts=4 et:
3
help()
4
{
5
cat <
6
b2h -- convert binary to decimal
7
USAGE: b2h [-h] binarynum
8
OPTIONS: -h help text
9
EXAMPLE: b2h 111010
10
will return 58
11
HELP
12
exit 0
13
}
14
error()
15
{
16
# print an error and exit
17
echo "$1"
18
exit 1
19
}
20
lastchar()
21
{
22
# return the last character of a string in $rval
23
if [ -z "$1" ]; then
24
# empty string
25
rval=""
26
return
27
fi
28
# wc puts some space behind the output this is why we need sed:
29
numofchar=`echo -n "$1" | wc -c | sed 's/ //g' `
30
# now cut out the last char
31
rval=`echo -n "$1" | cut -b $numofchar`
32
}
33
34
chop()
35
{
36&nbs
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......
运行了Oracle的Linux服务器更改主机名
假如要把主机名改为oratest。
$表示oracle用户操作;
#表示root用户操作。
DB:oracle10.2
OS:RHEL4.5
第一步,关闭数据库和监听,dbconsole:
$ dbshut
$ lsnrctl stop
第二部:
# hostname oratest
第三步:
# vi /etc/sysconfig/network
更改hostname参数。
第四步 ......
来源: http://www.xxlinux.com/linux/article/accidence/technique/20070125/7209.html
User Debug 日志记录
调试一个崩溃的程序的第一步是弄清哪里出了错。zSeries 上的Linux内核具有这样一个内置特性,它在用户进程崩溃时记录一些基本的调试信息。要启用这个特性,请以 root 用户身份执行如下命令:
echo 1 >& ......
这里记录Redhat Linux中的一些常用服务和配置工具。版本基于AS4。
1.Firewall
通过命令行配置:lokkit
图形界面配置:Applications->System Settings->Security Level
2.samba
/etc/init.d/smb start | /etc/init.d/smb stop | /etc/init.d/smb restart
或者
service smb start | service smb stop | servic ......