How to conditionally define a class? (ex. Xorg configuration)

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Thu Jan 21 19:26:25 CET 2010


On Thu, 21 Jan 2010, Thomas Lange wrote:

> Create a script class/99-radeon:
>
> #! /bin/bash
>
> # skip if class XORG is not defined
> grep -q XORG $FAI/class && exit 0
>
> ATI_RADEON_ID=$(lspci | grep VGA | grep ATI | grep Radeon)
> [ "$ATI_RADEON_ID" != "" ] && echo XORG_ATI

which could also be written as a one-liner (with error check builtin):

,----
| #!/bin/sh
|
| grep -q XORG $FAI/class || ! lspci | grep -q '\<VGA\>.*\<ATI\>.*\<Radeon\>' || echo XORG_ATI
`----

i.e.:

* there's no need to call bash to do that, as there's no bashism in there;
  dash and busybox ash will so that job faster
* there's no need to setup a variable (ATI_RADEON_ID)
* there's no need for several 'grep' forks; _one_ grep fork will do
  exactly the same job
* the '[ "$ATI_RADEON_ID" != "" ]' is odd; (mere rhetoric question) isn't
  this:

	[ "$ATI_RADEON_ID" ]

  doing the same thing, in a less convoluted manner?


Cheers,

-- 
Cristian


More information about the linux-fai mailing list