Execline Help: Need the Return Value and the Stdout of a Program

From: Scott Colby <scott_at_scolby.com>
Date: Tue, 23 Feb 2021 03:11:18 -0500

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
Received on Tue Feb 23 2021 - 08:11:18 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC