Hello,

I am having some difficulty translating the following shell script
to execline:

#!/usr/bin/env sh
file_loc=$(xmlstarlet sel -t -v '//File/Path' /etc/some-config.xml 2>&1)
# if //File/Path is missing from some-config.xml,
# xmlstarlet will have exited non-zero and we skip this
if test $? -eq 0
then
        if ! test -e "$file_loc"
        then
                create-file
        fi
fi
exec /usr/bin/s6-svscan /service

Here's what I have so far:

#!/usr/lib/execline/bin/execlineb -P
foreground {
  if -n {
    backtick -i file_loc {
      fdmove -c 2 1 xmlstarlet sel -t -v //File/Path /etc/some-config.xml
    }
    importas -iu file_loc file_loc test -e $file_loc
  }
  create-file
}
/usr/bin/s6-svscan /service

The problem is, `if -n` can't differentiate between the failure of
xmlstarlet within backtick and the failure of `test -e`.  I only
want create-file to be called if xmlstarlet succeeds and `test -e`
fails. I've tried various permutations of wrapping backtick and
importas with other if constructs, but couldn't find one that worked.
Looking at the other conditional commands, maybe I could take
advantage of ifthenelse setting $? before continuing the exec chain,
but I'm wondering if there is a better way.

How can I make such a script using execline?

Thank you,
Scott

Reply via email to