I have a command that outputs 2 lines,
% ./run
one
two
%
so the output is one\ntwo\n
How can I assign variables first
and second
to the first and second lines respectively?
I know how I could do both by running the command twice:
% first="$(./run | head -n 1)"
% second="$(./run | tail -n 1)"
I don't want to run ./run
twice, I only want to call it once (output might be different each time)
I could just store ./run
's output in a variable, then operate on the variable, but can I avoid having this temporary variable?
More and more high-level languages are adding destructuring assignments:
first, second = (./run).split('\n')
Can I accomplish something similar in zsh?