首页 > 代码库 > grep -n 查看字符串不为空失败
grep -n 查看字符串不为空失败
测试目的:
目的:测试/bin/grep -q "root" menu.lst的用途
结果:文本中是否包含root文字内容,如果是,返回0,如果不是,返回非零
#!/bin/bash
/bin/grep -q "root" menu.lst
rc=$?
if [ $rc -ne "0" ] ;then
echo "bad"
else
echo "good"
fi
~
目的:测试[ ](中间有一个空格)在grep中的用法
/sbin/ethtool eth0 |grep "Speed:[ ]1000Mb"
#!/bin/bash
#test script pass parmeter
echo $parmeter
if [ ! -z $parmeter ]; then
#如果parmeter不为空,打印full,说明有赋值
echo "full"
else
#如果parmeter为空,打印empty,说明没有任何的参数传递
echo "empty"
fi
执行如下:
[root@localhost /]# parmeter=author ./test.sh
author
full
[root@localhost /]# ./test.sh
empty
但是使用-n 替换掉 不管如何执行都打印full
-n 参数说明参数不为空
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。