reading /proc/cmdline

Klaus Steden klaus.steden at thomson.net
Wed Aug 24 23:06:06 UTC 2005


> Hello, all -
> 
> I use the following example of code in my kickstart file, to get values
> from /proc/cmdline to use later on during the install:
> 
> if grep -i -q "mystring[a-zA-Z0-9]" /proc/cmdline
> then
>     MYSTRING=`cat /proc/cmdline | sed 's/.*mystring=\([^ ]*\).*/\1/'`
> fi
> 
> I think Klaus in fact gave this to me.  However, I've ran into a few
> problems.  It seems that this does not like strings with periods in
> them, such as an IP address.
> 
> Since I know a bit less than nothing about regular expressions, I was
> hoping that someone could give me a hand with this.  I need to modify it
> to allow me to assign a dotted quad string to the MYSTRING variable.
> 
> Again, any help would be greatly appreciated.
> 
Hello again, Dan,

How about ...

if grep -iq "mystring=[a-zA-Z0-9]" /proc/cmdline
then
	MYSTRING=`cat /proc/cmdline | sed 's/.*mystring=\([^ ]*\).*/\1/'`
fi

Quick testing with sh on Linux tells me that it should preserve the dots. It
should just be deleting everything up to, but not including 'mystring=' and
whatever follows that, and then deleting everything after that string, and
returning the match.

REs can be tricky, though, so holler if you get stuck.

Klaus




More information about the Kickstart-list mailing list