统计指定后缀名文件行数
#!/bin/bash
ret=0
function cal_line()
{
if [ -f "$1" ]
then
name=$1
tmpname=${name##*.}
if [ "$tmpname" == "c" ] || [ "$tmpname" == "h" ]
then
local va=`grep -v "^$" $1 | wc -l | awk '{print $1}'`
ret=$va
return
fi
fi
for i in `ls $1`
do
if [ -d "$1/$i" ]
then
cal_line "$1/$i"
else
name="$1/$i"
tmpname=${name##*.}
if [ "$tmpname" == "cpp" ] || [ "$tmpname" == "h" ]
then
local va=`grep -v "^$" $1/$i | wc -l | awk '{print $1}'`
let ret=$ret+$va
fi
fi
done
}
cal_line $1
echo $ret
##在地址范围内寻找一个可以使用的ip地址
#!/bin/bash
for (( i=1; i < 255; i++ ))
do
ip="192.168.11.$i"
ping -w 1 $ip >& /dev/null
if (( $? ))
then
echo ""
echo "can use ip is "$ip
exit 0
else
echo -n "."
fi
done
#!/bin/bash
#数组的基本使用
tmparr=(1 2 3 "das")
len=${#tmparr[@]}
len=`expr $len - 1`
echo $len
echo ${tmparr[0]}
echo ${tmparr[$len]}
#将字符串转换为数组
tmpstr="1,2,3,4,5,6,7,8"
#${string//substring/repalcestring}
#上面的含义是将string中的子串substring全部换为replacestring字符串
tmparr=(${tmpstr//,/ }) #将,全部换为空格 然后用()转换为数组
echo ${#tmparr[@]}
echo ${tmparr[@]}
查看dbus服务和 对象
#!/bin/bash
if [[ $# < 1 ]]
then
echo "Usage show.list [dbus | servname[objname]]"
exit 0
fi
#列出虽有的活动服务
if [ "$1" = "dbus" ]
then
echo "***********************active service*************"
echo ""
dbus-send --system --print-reply --dest=org.freedesktop.DBus / org.freedesktop.DBus.ListActivatableNames | grep "string" | awk '{print $2}' | awk -F \" '{print $2}'
echo ""
echo "**************************************************"
exit 0
fi
if [ $# -eq 1 ]
then
dbus-send --system --type=method_call --print-reply --dest=$1 / org.freedesktop.DBus.Introspectable.Introspect
else
dbus-send --system --type=method_call --print-reply --dest=$1 /$2 org.freedesktop.DBus.Introspectable.Introspect
fi