On 5/29/2012 5:16 AM, Karl Eichwalder wrote:
Jan Engelhardt<jengelh@inai.de> writes:
On Tuesday 2012-05-29 09:48, Stephan Kulow wrote:
I don't know why kiwi's initrd calls an external tool for it either :)
haveKByte=`cat /proc/meminfo | grep MemFree | cut -f2 -d:| cut -f1 -dk`
cat has been obsolete for these kind of tasks, you can just use
grep MemFree /proc/meminfo
...
A grep and 2 cut commands? That's asking for awk (assuming that awk is available in your enviroment:
awk '/^MemFree:/ {print $2}' /proc/meminfo
or
awk '/^MemFree:/ {print $2; exit}' /proc/meminfo
You don't need awk or anything but the same shell that's already executing the script. GetVal () { DONE=false until $DONE ; do IFS=: read KEY VAL junk || DONE=: [[ "$KEY" == "$1" ]] && { echo $VAL ; DONE=: ; } done < $2 } GetVal MemFree /proc/meminfo This example is hard coded to always search field 1 and return field 2 intentionally just to keep the example simple. But only a little more complexity makes it fully generic, reading in an array per line instead of two variables, and allowing you to specify which fields you want to search and which fields you want to return, and which delimiter to use instead of hardcoding ":", and even specify how to recognize a command and ignore it. -- bkw -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org