替换字符
sed 's/:/ /g' #把:换成空格
tr '\n' '#' #把换行换成#
获取行数/字段数/字数
wc -w
wc -c
# -c Count bytes
# -l Count newlines
# -w Count words
# -L Print longest line length
判断
if [ $1 = "bind_key" ] && [ ! -z $2 ]; then
echo "set bind_key success"
elif [ $1 = "sn" ] && [ ! -z $2 ]; then
echo "set sn success"
fi
循环
whitelist=`nvram get test1 whitelist | sed 's/#/ /g'`
for loop in $whitelist
do
echo $loop | sed 's/,/ /g' >> /mnt/mtdblock7/aclwhite
done
for i in $(seq 1 10)
do
echo $(expr $i \* 3 + 1);
done
while true
do
checkbnt
sleep 1
done
加法
https://blog.csdn.net/zwx19921215/article/details/21098391
cnt=0
if [ $cnt -gt 0 ]; then
cnt=$(($cnt + 1))
fi
获取命令执行结果
res=`ifconfig eth0.2`
echo $res
函数调用
check_multi_network() {
reb=`ifconfig br-ran | wc -l`
if [ $reb -eq 0 ]; then
uci set network.ran=interface
uci set network.ran.ifname=eth0.3
uci set network.ran.type=bridge
uci set network.ran.proto=static
uci set network.ran.ipaddr=192.168.2.1
uci set network.ran.netmask=255.255.255.0
uci commit
/etc/init.d/network restart
fi
iwpriv ra0 set CountryRegion=1
iwpriv rai0 set CountryRegionABand=6
}
while true
do
check_multi_network
sleep 5
done
递归所有文件
#递归列出目录下的所有文件名(不包括目录),并且去掉空行
ls -lR |grep -v ^d|awk '{print $9}' |tr -s '\n'
去重
https://blog.csdn.net/laobai1015/article/details/91455406
大小写转换
tr '[a-z]' '[A-Z]' #小写转大写
tr '[A-Z]' '[a-z]' #大写转小写
生成软链接
ln -s /tmp/log.txt log.txt #把tmp目录下的文件创建一个快捷方式到这里
ln -s /tmp tmp #在当前目录下也能访问tmp文件夹