Accessing boot: prompt options inside KS script

Klaus Steden klaus.steden at thomson.net
Sat May 21 19:17:22 UTC 2005


> Hi Klaus,
> 
> Thanks for the /proc/cmd tip.
> 
> I extracted the commandline options like this:
> 
> ip=`grep ip /proc/cmdline | sed 's/.*ip=//' |sed 's/ .*//'`
> 
> The first grep is there to return a blank line incase the option is not
> present at all (else the second sed would return the portion of the line
> after the first whitespace even though ip= was not present).
> 
> The two seds split up the work, the first returns the entire command line
> past ip=, and the second then retum the first part up to the first blank
> space. Since all the command line options are space delimted, this works
> just fine.
> 
> Busybox doesn't include awk, otherwise it would have been easier to just
> use that. But awk is derived from sed, so sed does fine as well.
> 
Christian - here is the sort of syntax I use to do that (just in case anyone
likes other ways, too)

if grep -i -q "ip=[0-9]" /proc/cmdline
then
    ip=`cat /proc/cmdline | sed 's/.*ip=\([^ ]*\).*/\1/'`
fi

The sed expression returns a copy of everything -after- "ip=" up to but not
including the first blank space (so, the value you want).

Klaus




More information about the Kickstart-list mailing list