You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to eval the multiline output of a command #3993
I've been working on Vaulted trying to get vaulted env to work properly for fish (apparently I screwed up the initial implementation, now I'm trying to fix it 😛).
The output is fish syntax for setting variables, something like:
# To load these variables into your shell, execute:# eval (vaulted env test)set-gx TEST "test value";
set-gx OTHER "another test";
Unfortunately, this ends up passing all of the lines into eval as individual arguments. eval concatenates them all with spaces, making it one big run-on command. Since the output starts with a comment character, this effectively comments out the entire script and nothing gets run.
After reviewing #159 and fiddling with various things, I've found one thing that actually works without polluting the environment with extraneous variables:
begin; vaulted envtest|read-lz cmds; andeval$cmds; end
But this feels like I'm taking the long way to getting the script into eval. It seems like fish would have a more straightforward way of piping the output of a command into eval, something that would keep the script intact rather than splitting it into lines and then recombining it in a different way. I hope I just missed something in fish and am just making this harder than it needs to be! lol
fish, version 2.5.0
FWIW, bash handles it through a quoted subshell this way:
You should not include comments in output meant to be handed to eval; even in the context of other shells like bash. As @zanchey suggested if you want to retain that pattern it is better to tell your users to do vaulted env test | source.
Excellent, this is exactly the type of thing I was hoping I was overlooking! It didn't even occur to me to pipe the script into source (which, unfortunately, doesn't work in bash or zsh).
I do agree on not including comments in the script that's passed to the shell. In fact, our original implementation only included the comments when a TTY was present. Since vaulted's primary purpose is keeping unencrypted secrets off your disk, we wanted to provide suggested commands to help people ensure that happened.
Piping into source solves the issue in this case, but I'm still left wondering if there's a way to pass the unaltered contents of a command in as an argument to another command (without temporarily storing it in a variable, that is)?
Activity
zanchey commentedon Apr 27, 2017
Is there a reason you need to use
evalrather thansource, which you can pipe into?krader1961 commentedon Apr 27, 2017
You should not include comments in output meant to be handed to
eval; even in the context of other shells like bash. As @zanchey suggested if you want to retain that pattern it is better to tell your users to dovaulted env test | source.miquella commentedon Apr 27, 2017
Excellent, this is exactly the type of thing I was hoping I was overlooking! It didn't even occur to me to pipe the script into
source(which, unfortunately, doesn't work inbashorzsh).I do agree on not including comments in the script that's passed to the shell. In fact, our original implementation only included the comments when a TTY was present. Since
vaulted's primary purpose is keeping unencrypted secrets off your disk, we wanted to provide suggested commands to help people ensure that happened.Thank you so much!
miquella commentedon Apr 27, 2017
Piping into
sourcesolves the issue in this case, but I'm still left wondering if there's a way to pass the unaltered contents of a command in as an argument to another command (without temporarily storing it in a variable, that is)?krader1961 commentedon Apr 27, 2017
Not at this time. See issue #159.
miquella commentedon Apr 27, 2017
Hmm, okay. Thanks, @krader1961!
Fix suggested fish command to load variables
Fix suggested fish command to load variables
Added main sub function for fish environments.
Fix fish activation
Generate fish compatible docker-env hint
Generate fish compatible docker-env hint