Found something interesting....

Per the gnu bash reference manual......

-f file
 True if file exists and is a regular file.

-h file
True if file exists and is a symbolic link.

-x file
 True if file exists and is executable.

Function as built from rc

check_script_status()
{
   # $i is set when called
   if [ ! -f ${i} ]; then
      log_warning_msg "${i} is not a valid symlink." 
      SCRIPT_STAT="1"
   fi

   if [ ! -x ${i} ]; then
      log_warning_msg "${i} is not executable, skipping."
      SCRIPT_STAT="1"
   fi
}


So the construct/function in rc should be 

check_script_status()
{
   # $i is set when called
   if [ ! -x ${i} ]; then
      log_warning_msg "${i} is either missing and or not executable,
      skipping." SCRIPT_STAT="1"
   fi
}

This check is meaningless and misleading

if [ ! -f ${i} ]; then
      log_warning_msg "${i} is not a valid symlink." 
      SCRIPT_STAT="1"
fi

You are not checking for a symlink that would be 
if [ ! -h ${i} ]; then if you were testing for a symlink

So it should stand as....

# Checks for a symlink and the file it points to exist
# and is executable.
# Called: check_script_status <symlink>
# where <symlink> is a "pointer" to the script to check
# Sets: Local SCRIPT_STAT, "0" = OK, "1" = FAILURE
#
function check_script_status {
   local i="${1}"
   # initialize status as "OK"
   SCRIPT_STAT="0"
   if [[ ! -h "${i}" ]]; then
      log_warning_msg "${i} is not a valid symlink." 
      SCRIPT_STAT="1"
   fi
   if [[ ! -x "${i}" ]]; then
      log_warning_msg "${i} is not executable, skipping."
      SCRIPT_STAT="1"
   fi
   return
}

That is if one really wanted to check the symlink and if the file 
pointed to by the symlink exists and is executable.


Pierre Labastie:

You stated.....

"It's preferable to use quotes around any variable you do not know in
advance: script="$1" "

So how come the rc script (as above, cut and pasted from the rc
script himself ) is the same as the example I posted ?

You see the variable in 'if [ ! -h ${i} ]; then' (copied and pasted
from the current script rc) would then suffer the same breakage.

Now I am not disagreeing with you, but on the contrary, if you are
correcting some one should the boot scripts not follow your example?

The code fragment I posted previously was only an example for
discussion and certainly not production code.

Hence this is one of the reasons I stated that the boot scripts needs
a general cleanup and if cleaning them up a standard format.

-- 
http://lists.linuxfromscratch.org/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Do not top post on this list.

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

http://en.wikipedia.org/wiki/Posting_style

Reply via email to