Re: [execline] Conditional export

From: Carlos Eduardo <carana2099_at_gmail.com>
Date: Thu, 23 Mar 2023 09:58:00 -0300

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

This archive was generated by hypermail 2.4.0 : Thu Mar 23 2023 - 13:58:41 CET