#Shell job control and variable assignments / value returns?

1 messages ยท Page 1 of 1 (latest)

pearl magnet
#

Is there any way to actually reference the result of something done in the background (&) in the shell after awaiting it ?
E.g. something like this:

( hi=$( container | from alpine | with-exec echo hi) ) &
( bye=$( container | from alpine | with-exec echo bye) ) &
.wait
$hi | stdout
$bye | stdout
graceful bone
pearl magnet
#

ah ok ๐Ÿ˜…

#

I happen to have explicit cache invalidation markers in some of my withExecs in the actual use-case here, to make sure they always run fresh (because they depend on external calls that might have new data), so this won't work for me unfortunately ๐Ÿ™

graceful bone
#

so if your module receives a --cache-key argument it can use that or otherwise generate a new one on each run

#

it's tricky to do this in some other way because bash doesn't have a native way to achieve this and the way people usually resort to is to use mkfifo or output things to files which is ๐Ÿ˜ฌ

pearl magnet
#

yeah the cache key would work

#

output things to files
this is what I'm probably gonna do ๐Ÿ˜…

#

in my actual use-case the results are dagger.Directory so I think I'll just export that and then pass $(host | directory ...) in places where I would have used the variable (/ second function invocation)

graceful bone
graceful bone
pearl magnet
#

...and wouldn't the cache hit technically also be a disk read?

graceful bone
pearl magnet
#

thanks for the insight ! ๐Ÿ™