1 |
On Thu, 18 Nov 2004, kosmikus wrote: |
2 |
|
3 |
<snip what everyone's talked about already> |
4 |
|
5 |
> function get-memory-total() { |
6 |
> cat /proc/meminfo | grep MemTotal | sed -r "s/[^0-9]*([0-9]+).*/\1/" |
7 |
> } |
8 |
|
9 |
cat | grep | (sed|awk) lines have always bothered me to no end. How |
10 |
about, instead, one of the following function bodies: |
11 |
|
12 |
awk '/MemTotal/ { print $2}' /proc/meminfo |
13 |
sed -r -e '/MemTotal/!d' -e 's/[^0-9]*([0-9]+).*/\1/' /proc/meminfo |
14 |
perl -ne '/MemTotal:\s+(\d+)/ && print "$1\n"' /proc/meminfoo |
15 |
grep MemTotal | (read tag size units; echo $size) |
16 |
|
17 |
Normally, I wouldn't bring it up, but there's *so* many ways to do that |
18 |
better, it's sad. Note that I could've listed many more, but that |
19 |
would've been sad as well. (Actually, even this much is somewhat sad.) |
20 |
Personally, I'd vote for the first or third of this group. |
21 |
|
22 |
Ed |
23 |
|
24 |
-- |
25 |
gentoo-dev@g.o mailing list |