I'm trying to append an element to an array.
What I tried is:
for i in (seq 10)
set children $children $line[$i]
end
but that does not add a new element. It creates a single variable containing all of children then a space and $line[$i].
Using fish version 2.7.1-1113-ge598cb23 (3.0 pre-alpha) you can use set -a
(append) or set -p
(prepend).
set -l array "tiny tim" bob
set -l children joe elias matt
echo $children
for i in (seq 2)
set -a children $array[$i]
end
echo $children
Output:
joe elias matt
joe elias matt tiny tim bob
You could also use the string command which should work on most recent versions of fish.
set -l array "tiny tim" bob
set -l children joe elias matt
echo $children
for i in (seq 2)
set children (string join " " $children $array[$i])
end
echo $children
Output:
joe elias matt
joe elias matt tiny tim bob
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