WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Noticed first part of init could be written different. ( Wrong...)  (Read 2019 times)

Offline SunBurnt

  • Full Member
  • ***
  • Posts: 102
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
« Last Edit: August 18, 2011, 12:07:43 PM by SunBurnt »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11639
Re: Noticed first part of init could be written different.
« Reply #1 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
« Last Edit: August 18, 2011, 02:33:40 PM by Rich »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Noticed first part of init could be written different.
« Reply #2 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.
The only barriers that can stop you are the ones you create yourself.

Offline SunBurnt

  • Full Member
  • ***
  • Posts: 102
Re: Noticed first part of init could be written different.
« Reply #3 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.
« Last Edit: August 18, 2011, 12:07:13 PM by SunBurnt »