×î½üÔÚ¿´bash shell£¬ ×¼±¸ÕÕè»»¢×Ô¼ºÐ´¸ö²éѯÌí¼ÓµÄС½Å±¾£¬ÏëʵÏֵŦÄÜÊÇ£ºÓû§ÊäÈëÒ»¸ö×Ö·û´®È»ºó²éÕÒpasswdÊÇ·ñÓÐÕâ¸ö×Ö·û´®£¬Èç¹ûÓÐÊä³ö×Ö·û´®£¬Èç¹ûûÓÐÔò°ÑÕâ¶Î×Ö·û´®Ìí¼Óµ½passwd¡£ÎÒÏëÓÃifÀ´ÅжÏÓû§ÊäÈëµÄ×Ö¶ÎÊÇ·ñÔÚpasswd´æÔÚ£¬µ«ÊÇʵÔÚÏë²»³öÀ´ÈçºÎʵÏÖ¡£ Èç¹û²»ÓÃifÖ»ÊÇÅжÏÓû§ÊäÈëµÄ×Ö¶ÎÊÇ·ñ´æÔÚ£¬ÕâÑù¿ÉÒÔʵÏÖ:
read -p "please input :" b
cat passwd | grep "$b" || echo "thiere is no "$b" in this file!"
µ«ÊÇÈç¹ûÏë¼ÓÈëifÅжÏÓï¾äÊÇÒª°ÑÕâЩ¶¼Ð´ÔÚ[]ÀïÃæô£¿»¹ÊÇÓÐʲô¸ü¼òµ¥µÄ·½·¨¿É´ï³É£¿
linvex ÓÚ 2011-09-03 15:51:53·¢±í:
ÄãÔõô²»ÊÔÊÔÕâÑù£º
read -p "please input:" b
u=`cat passed | grep -c "$b"`
if [ ¡±$u" = 1 ];then
echo $b
else
echo "there is no ¡°$b" in this file!"
echo " ¡°$b" will be add into passwd !"
"$b" >> passwd
fi
òËÆÎÒÃÇû¸Äʲô£¬µ«ÊÇÕâÑù¸üÊÊÓÃÓÚ¶àÏß³ÌÔËÐУ¬Äã¿ÉÒÔÏëÏóһϣ¬ÎÒÃÇÔÚ²éÕÒʱÍùÍù¶¼ÊDz²»µ½µÄ£¬ÕâÑùÒ»¸Ä£¬¿ÉÒÔ¼õÉÙcpuµÄÔËËãÁ¿£¬¾ÍÊÇËùνµÄÓÅ»¯³Ìʽ
hhbh1991 ÓÚ 2011-09-03 14:35:50·¢±í:
ÎÒ¾õµÃÉÏÃæÁ½ÖÖÂùºÃµÄ£¬¿ÉÒÔѧϰÏÂ
gwssgc ÓÚ 2011-08-23 16:48:47·¢±í:
[i=s] ±¾Ìû×îºóÓÉ gwssgc ÓÚ 2011-8-23 16:51 ±à¼ [/i]
¸ÐлLS£¬²»¹ýÓÃÄãµÄ·½·¨³ÌÐò²»Äܳɹ¦ÔËÐС£ÎÒÊÇÕâôʵÏÖµÄ
#!/bin/bash
read -p "please input:" b
u=`cat passed | grep -c "$b"`
if [ ¡±$u" = 0 ];then
echo "there is no ¡°$b" in this file!"
echo " ¡°$b" will be add into passwd !"
"$b" >> passwd
else
echo $b
fi
zenghuan88 ÓÚ 2011-08-23 15:56:18·¢±í:
»òÐí¿ÉÒÔÕâÑùд£º
read -p "please input :" b
if [ -z `cat passwd | grep "$b"` ] # Èç¹û×Ö·û´®Îª¿Õ£¬Ôò˵Ã÷ÔÚpasswdÀï²»´æÔÚ $b
then
echo "thiere is no "$b" in this file!"
exit 0
fi