I have a command that outputs a bunch of stuff e.g. running mycmd
will give:
foobar
derp derp
like so
etc
Some of these lines will have spaces in them.
How do I read these into an array in zsh such that ${arr[1]}
gives foobar
, ${arr[2]}
gives derp derp
etc.
I have tried something like but it seems to split the array on chars not newlines.
IFS=$'\n' read -d '' -r arr <<< "$(mycmd)"
i.e. ${arr[1]}
gives f
when it should give foobar
Okay its actually very simple:
IFS=$'\n' arr=($(mycmd))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With