Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 92099 - if.. then vs. if... <nl> then
Summary: if.. then vs. if... <nl> then
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: SpanKY
Depends on:
Reported: 2005-05-10 03:06 UTC by Mark Dominik Bürkle
Modified: 2006-10-11 08:42 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Mark Dominik Bürkle 2005-05-10 03:06:27 UTC
Hello Vapier,

would You mind to stop changing

"if ... ; then"


"if ...

with every update back and forth?

Thank You,
Comment 1 Mark Dominik Bürkle 2005-05-10 03:36:44 UTC
Hi SpanKY,

btw. thanks for all the work You do!!

But I see no reason to change sth. like

-       if [ -e /etc/conf.d/local.stop ]
-       then
+       if [[ -e /etc/conf.d/local.stop ]] ; then

either, as "[[ ... ]]" in this case just will not do word splitting and filename expansion (and more?), which would not occur anyways because there are no variable parts in this file name, and I find it much clearer to write

  if test -e "$somefileVar"; then

instead of

  if [[ -e $somefileVar ]]

Though the latter nicely shows the capabilities of bash, putting "" around filename variables will work everywhere... but it doesn't make a difference here.

+# $Header: /var/cvsroot/gentoo-src/rc-scripts/init.d/localmount,v 2005/02/19 19:47:53 vapier Exp $
+       local usbfs=$(grep -Fow usbfs /proc/filesystems ||
+               grep -Fow usbdevfs /proc/filesystems)
+       if [[ -n ${usbfs} ]] && \
+          [[ -e /proc/bus/usb && ! -e /proc/bus/usb/devices ]]

You might as well be interested in grep's "-q / --quiet" option, which does not output anything... though in this case You certainly want output. Consider combining multiple grep searches into one with "-e ... -e ...", as this would be two less fork()/exec()s in this case -- doesn't matter on todays hardware, but on some old 486 (or even 386) all those expenses will sure hurt performance:

        local usbfs=$(grep -Fow usbfs /proc/filesystems ||
                grep -Fow usbdevfs /proc/filesystems)
        local usbfs=$(grep -owe usbfs -e usbdevfs /proc/filesystems)
        local usbfs=$(grep -owEe 'usb(dev)?fs' /proc/filesystems)

And maybe (though there should only be one of them in /proc/filesystems) a combination with "-m 1"... but I'm getting way too deep into it.

Comment 2 Radek Podgorny 2005-05-10 03:42:16 UTC
Hi, if this is going to be an argument, my opinion is to keep the "then" on the same line :-)
Comment 3 SpanKY gentoo-dev 2005-05-10 05:15:46 UTC
ive never written code of the form
if ...

regardless, see the STYLE file in baselayout
Comment 4 Mark Dominik Bürkle 2005-05-10 10:23:47 UTC
thanks for the hint, but I didn't find "style" in baselayout:

equery files baselayout |
 while read f rest; do
  test -L "$f" -o -d "$f" && continue
  test ! -e "$f" && continue
  echo "$f"
 done |
 xargs -r grep -i --color=tty -e style

Would You mind to give me another hint?
No matter if You do: thanks, sorry to take Your time!
Comment 5 Mark Dominik Bürkle 2006-10-11 08:42:47 UTC
closing bug, may be purged from the DB.
(New status should be closed invalid.)