Re: [PATCH 1/3]: Replace kernel/timeconst.pl with kernel/timeconst.sh

Michal Jaegermann
2009-01-04T08:02:28Z

On Sat, Jan 03, 2009 at 07:36:04PM -0600, Rob Landley wrote:
> On Saturday 03 January 2009 06:28:22 Ingo Oeser wrote:
> > > +for i in "MSEC 1000" "USEC 1000000"
> > > +do
> > > + NAME=$(echo $i | awk '{print $1}')
> >
> > cut -d' ' -f1 does the same
> >
> > > + PERIOD=$(echo $i | awk '{print $2}')
> >
> > cut -d' ' -f2 does the same
>
> From a standards perspective
> http://www.opengroup.org/onlinepubs/9699919799/utilities/cut.html vs
> http://www.opengroup.org/onlinepubs/9699919799/utilities/awk.html is probably
> a wash, but from a simplicity perspective using the tool that _isn't_ its own
> programming language is probably a win. :)

Vagaries of 'cut' aside you can limit yourself here to just shell:

set_name_period () {
NAME=$1 ; PERIOD=$2
}
for i in "MSEC 1000" "USEC 1000000"
do
set_name_period $i
....
done

or you may skip a shell function and do 'set $i' within a loop plus
assignments of $1 and $2 to NAME and PERIOD but that overwrites original
positional parameters (which may be already not important).

Michał