How to use conditionals

Gerard Beekmans gerard at linuxfromscratch.org
Thu Jun 17 14:01:39 PDT 2004


Hey guys,

I checked out CVS and build nALFS and am trying to use conditionals now
to see how it all works. So far not much luck.

First off, there's a mistake in the documentation: in
docs/syntax_doc/alfs_dtd/elem_if.xml

The following given example doesn't quite work:

<screen><userinput>
<execute command="touch /tmp/foo" />
<if test="[-r /tmp/foo">
<then><execute command="echo this should be executed."
/></then>
<else><execute command="echo this should not be executed."
/></else>
</if>
</userinput></screen>

That [ before '-r' should be removed.

Now, consider this piece of profile as an example:

        <stage name="Test">
                <if test="-r /etc/passwd">
                <then>
                        <textdump>
                                <file>/testpassed</file>
                                <content>=passed</content>
                        </textdump>
                </then>
                <else>
                        <textdump>
                                <file>/testfailed</file>
                                <content>=failed</content>
                        </textdump>
                </else>
                </if>
        </stage>


Either I'm doing something wrong, or it's not working as it should.
Output in nALFS is:

I: Executing __profile...
I:
I:     test -r /etc/passwd
I: Log file stored in:
I: /home/gerard/.nALFS/packages/test.xml
I: Execution successfully done.
I: Total time executing: 00:00:00

And neither /testpassed or /testfiled exist after it runs. The test.xml
log contains:

  <package mode="start">Thu, 17 Jun 2004 14:57:51 -0600</package>
  <stage mode="start">Thu, 17 Jun 2004 14:57:51 -0600</stage>
  <handler_action>    test -r /etc/passwd</handler_action>
  <then mode="start">Thu, 17 Jun 2004 14:57:51 -0600</then>
  <then mode="end" status="done">Thu, 17 Jun 2004 14:57:51 -0600</then>
  <stage mode="end" status="done">Thu, 17 Jun 2004 14:57:51
-0600</stage>
  <package mode="end" status="done">Thu, 17 Jun 2004 14:57:51
-0600</package>

So it looks it enters <then> (as it should) but doens't run anything
there?




-- 
Gerard Beekmans

/* If Linux doesn't have the solution, you have the wrong problem */




More information about the alfs-discuss mailing list