Re: [execline] Conditional export

From: Petr Vaněk <arkamar_at_atlas.cz>
Date: Thu, 23 Mar 2023 14:11:47 +0100

On Thu, Mar 23, 2023 at 09:58:00AM -0300, Carlos Eduardo wrote:
> I'd
>
> define FILE file
> backtick -x EXISTS { if { eltest -f $FILE } s6-echo -- $FILE }
> env
>
> -x removes EXISTS from the environment if the "if" fails.

Thanks a lot! I should have read the documentation more carefully, I
completely overlooked "or if prog1... crashes or exits nonzero" part of
backtick -x :(

> (still impressed by the creative use of importas -us).
>
> Em qui., 23 de mar. de 2023 às 09:44, Petr Vaněk <arkamar_at_atlas.cz> escreveu:
> >
> > Hi execline enthusiasts,
> >
> > I am trying to write an execline script which conditionally exports
> > variable only if a given file exists. I am basically trying to mimic
> > this shell script:
> >
> > ```
> > #! /bin/sh
> >
> > FILE="file"
> >
> > if [ -f "${FILE}" ]; then
> > EXISTS="${FILE}"
> > fi
> >
> > export EXISTS
> >
> > env
> > ```
> >
> > I have come up with following solution, which does what I want but I am
> > wondering if there is a better way of expressing this in execline?
> >
> > ```
> > #! /bin/execlineb -P
> >
> > define FILE "file"
> >
> > backtick EXPORTER {
> > foreground {
> > if { eltest -f "${FILE}" }
> > echo export EXISTS "${FILE}"
> > }
> > }
> >
> > importas -us EXPORTER EXPORTER "${EXPORTER}"
> >
> > env
> > ```
> >
> > Cheers,
> > Petr
Received on Thu Mar 23 2023 - 14:11:47 CET

This archive was generated by hypermail 2.4.0 : Thu Mar 23 2023 - 14:12:18 CET