Tiny Core Linux

General TC => General TC Talk => Topic started by: SunBurnt on August 18, 2011, 08:53:04 AM

Title: Noticed first part of init could be written different. ( Wrong...)
Post by: SunBurnt on August 18, 2011, 08:53:04 AM
I finally got some time to stare at TC`s boot scripts more and noticed this:
Not trying to be picky, but wouldn`t this first part of init:
Code: [Select]
#!/bin/sh
mount proc
grep -qw multivt /proc/cmdline && mv /etc/inittab-save /etc/inittab
if grep -qw embed /proc/cmdline; then
  umount proc
  exec /sbin/init
fi
umount proc
Be better written as:
Code: [Select]
#!/bin/sh
mount proc
grep -qw multivt /proc/cmdline && mv /etc/inittab-save /etc/inittab
umount proc
grep -qw embed /proc/cmdline && exec /sbin/init
Title: Re: Noticed first part of init could be written different.
Post by: Rich on August 18, 2011, 09:21:08 AM
Hi SunBurnt
I don't deal with scripts much, but both ways look like they'll work. However, readability is also
important. Without reading a single line of code I can look at the first version and know a conditional
statement is there, with the second I actually have to read the line to know that. When dealing with a
large script the first way will make it easier to figure out what's going on.

   [EDIT]: Spelling correction
Title: Re: Noticed first part of init could be written different.
Post by: curaga on August 18, 2011, 10:03:35 AM
No, that wouldn't work:

Quote
umount proc
grep -qw embed /proc/cmdline && exec /sbin/init

In your version, proc is already gone by the grep.
Title: Re: Noticed first part of init could be written different.
Post by: SunBurnt on August 18, 2011, 11:27:17 AM
Rich; The line before it was done that way ( no "if [....." ), it seemed good.

curaga; You`re right of course, didn`t look at the content of the command.