[Ubuntu-zh] bash脚本中-z和-n问题
Peter Derek
1and1get2在gmail.com
星期二 十二月 20 12:06:11 UTC 2011
ÊܽÌÁË
ÔÚ 2011-12-20 ÏÂÎç3:49£¬"sanye" <xbapj1在gmail.com>дµÀ£º
> Ï꾡µÄÎĵµÔÚinfo coreutils 'test invocation'
> man³öÀ´µÄºÜ¼òÂÔ
> Àïͷ˵µÃºÜÃ÷°×
>
> These options test string characteristics. You may need to quote
> STRING arguments for the shell. For example:
>
> test -n "$V"
>
> The quotes here prevent the wrong arguments from being passed to
> `test' if `$V' is empty or contains special characters.
>
> À×·æÄÄ
> On Tue, 2011-12-20 at 15:36 +0800, Ô¬·É wrote:
> > ¾²âÊÔ£¬¼ÓÁËÒýºÅ¾ÍÕýÈ·ÁË¡£
> > ¡°ÔÚÖÐÀ¨ºÅÄڵıäÁ¿£¬×îºÃ¶¼ÒÔË«ÒýºÅÀ¨ºÅÆðÀ´¡±
> > ¼ûÄñ¸çp382
> >
> > ÔÚ 2011Äê12ÔÂ20ÈÕ ÏÂÎç3:22£¬sanye <xbapj1在gmail.com>дµÀ£º
> >
> > > ÎÒÔõô¼ÇµÃÊÇ
> > > if [ -n "$str" ];then
> > > echo "1"
> > > fi
> > >
> > > if [ -z "$str" ];then
> > > echo "2"
> > > fi
> > >
> > > ¶øÇÒ£¬OTÁË°É
> > > On Tue, 2011-12-20 at 15:09 +0800, leon wrote:
> > > > ÔÚѧϰbash±à³ÌʱÓöµ½µÄÎÊÌâ
> > > > ½²½âÖÐÌáʾbash½Å±¾ÖÐ
> > > > -n µ±×Ö·û´®²»Îª¿ÕʱΪÕæ
> > > > -z µ±×Ö·û´®Îª¿ÕʱΪÕæ
> > > >
> > > > ÄÇôÒÔϽű¾
> > > > str=""
> > > >
> > > > if [ -n $str ]
> > > > then
> > > > echo "1"
> > > > fi
> > > >
> > > > if [ -z $str ]
> > > > then
> > > > echo "2"
> > > > fi
> > > >
> > > > Ö´ÐÐʱ»áÊä³ö
> > > > 1
> > > > 2
> > > > Ϊʲô»áÁ½¸ö¶¼Êä³öÄØ£¿
> > > > strΪ¿ÕͬʱҲ²»Îª¿Õ£¿£¿
> > > > »¹ÊÇÎÒÀí½âÓÐÎó»òÕßÉèÖÃÓÐÎ󣿣¿
> > > > ¨D¨D¨D¨D
> > > >
> > >
> Èç¹û˵ÎÒÃÇÊÇÀËÂþÖ÷ÒåÕߣ¬ÊDz»¿É¾ÈÒ©µÄÀíÏëÖ÷Òå·Ö×Ó£¬ÎÒÃÇÏëµÄ¶¼ÊDz»¿ÉÄܵÄÊÂÇ飬ÄÇô£¬ÎÒÃǽ«Ò»Ç§ÁãÒ»´ÎµÄ»Ø´ð£¬Êǵģ¬ÎÒÃǾÍÊÇÕâÑùµÄÈË¡£ÖÒÓÚÀíÏ룬Ãæ¶ÔÏÖʵ¡£
> > > >
> > > > ÈôΪ×ÔÓɹʣ¬ÐèÓйýǽÌÝ <http://goo.gl/5liFC>
> > > > -------------- ÏÂÒ»²¿·Ö --------------
> > > > Ò»¸öHTML¸½¼þ±»ÒƳý...
> > > > URL: <
> > >
> https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20111220/ed116556/attachment.html
> > > >
> > >
> > >
> > >
> > > --
> > > ubuntu-zh mailing list
> > > ubuntu-zh在lists.ubuntu.com
> > > https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh
> > >
> > -------------- ÏÂÒ»²¿·Ö --------------
> > Ò»¸öHTML¸½¼þ±»ÒƳý...
> > URL: <
> https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20111220/bda47c06/attachment.html
> >
>
>
>
> --
> ubuntu-zh mailing list
> ubuntu-zh在lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh
>
-------------- ÏÂÒ»²¿·Ö --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: <https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20111220/bf43351f/attachment.html>
关于邮件列表 ubuntu-zh 的更多信息