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
Re: Execline Help: Need the Return Value and the Stdout of a Program
#!/usr/lib/execline/bin/execlineb -P foreground { backtick -i file_loc { fdmove -c 2 1 xmlstarlet sel -t -v //File/Path /etc/some-config.xml } importas -iu file_loc file_loc if -n { test -e $file_loc } create-file } /usr/bin/s6-svscan /service LGTM. 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, so the script could become: #!/usr/lib/execline/bin/execlineb -P foreground { backtick -E file_loc { fdmove -c 2 1 xmlstarlet sel -t -v //File/Path /etc/some-config.xml } if -n { test -e $file_loc } create-file } /usr/bin/s6-svscan /service 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. As another note, "foreground", "backtick", and "fdmove" need to be in the caller's PATH in order to be found. If your execlineb binary is in /usr/lib/execline/bin/execlineb, then chances are the other binaries are as well, so you should make sure /usr/lib/execline/bin is in your PATH prior to running this script. As far as I know, only Debian and Ubuntu install execline there; if you're using the Debian or Ubuntu packages, /usr/bin/execlineb is a wrapper that adds /usr/lib/execline/bin to your PATH then execs into the real execlineb; so you should use the #!/usr/bin/execlineb shebang. (I do not condone the Debian package's way of installing execline, but they found a way to make it work without breaking the other skarnet.org packages, so it's all I can ask for and the rest is their policy to decide on.) -- Laurent
Re: Execline Help: Need the Return Value and the Stdout of a Program
On Tue, Feb 23, 2021 at 03:11:18AM -0500, Scott Colby wrote: > 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 > Hi! If i understood correctly, this should do what you want: #!/usr/lib/execline/bin/execlineb -P foreground { backtick -i file_loc { fdmove -c 2 1 xmlstarlet sel -t -v //File/Path /etc/some-config.xml } importas -iu file_loc file_loc if -n { test -e $file_loc } create-file } /usr/bin/s6-svscan /service Move the backtick out of the if, if xmlstartlet fails backtick (-i) will not execute the if (and importas) at all.