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.
(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 - 13:58:00 CET