Re: Execline Help: Need the Return Value and the Stdout of a Program
Thanks for the quick responses! On Tue, Feb 23, 2021, at 03:38, Alex Raschi wrote: > If i understood correctly, this should do what you want: This was exactly it. Thanks for the help. On Tue, Feb 23, 2021, at 06:31, Laurent Bercot wrote: > As an addition, if you use execline-2.8.* then the -i option > to backtick is the default behaviour, and there is a -E option to > perform the 'importas' part automatically, I like this option: it would really cut down on the boilerplate of specifying the variable name 3 times. I tried to use it at first, but my distro-supplied version is too old to have it, unfortunately. > You could also add "unexport ?" between the foreground block and > the s6-svscan execution, to ensure the ? environment variable > added by foreground does not spill into the whole supervision tree. Very good point; I will do so. > {Debian-specific things} Indeed I am using Debian's packaged version. I had noticed that the various commands were not on the default PATH, and I had manually added /usr/lib/execline/bin to it. My installation (execline 2.5.0.1-3 on Debian Buster) doesn't have the wrapper in /usr/bin/execlineb. I thought that was strange, as it means the packaged version of execline is broken unless you make edits to the PATH... Thanks, Scott
Execline Help: Need the Return Value and the Stdout of a Program
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