31mon2replicat in programmingReturning (echoing) lists in Fish shellI'm new to Fish and really liking it so far but the list type is really confusing me. Something that I find really non-intuitive about fish is the list data type. You can set a list like this set my_list a b c echo my_list[1] #a But if you try this it doesnt work: function mklist echo a b c end set lst (mklist) echo $lst[1] # a b c Putting the echo in quotes doesnt work either. You can do: function mklist echo a b c end set lst (string split " " -- (mklist)) echo $lst[1] # a But needing to always split your return values is kinda terrible. So it seems like what fish expects you to do is echo multiple lines. function mklist echo a echo b echo c end set lst (mklist) echo $lst[1] # a Its just very weird to me that it doesnt understand a comma delimited string to be a list. I feel like I must be missing something. Edit: FWIW I think I get why they designed it like this after thinking some more. It just feels weird. This requires you to be explicit about returning lists. Otherwise any echo with spaces would be treated as a list and not a single value
TechnoCat - 1monA list in Fish is basically a string stored in an environment variable with a specified delimiter. https://fishshell.com/docs/current/language.html#lists 1
TechnoCat - 1monAlright, reading into it a bit more they are not just special strings. Somehow fish marks those variables as special list values. But as soon as you echo them they get concatenated with spaces. 1
replicat in programming
Returning (echoing) lists in Fish shell
I'm new to Fish and really liking it so far but the
listtype is really confusing me.Something that I find really non-intuitive about fish is the
listdata type.You can set a list like this
But if you try this it doesnt work:
Putting the echo in quotes doesnt work either.
You can do:
But needing to always split your return values is kinda terrible.
So it seems like what fish expects you to do is echo multiple lines.
Its just very weird to me that it doesnt understand a comma delimited string to be a list.
I feel like I must be missing something.
Edit: FWIW I think I get why they designed it like this after thinking some more. It just feels weird.
This requires you to be explicit about returning lists. Otherwise any echo with spaces would be treated as a list and not a single value
A list in Fish is basically a string stored in an environment variable with a specified delimiter.
Alright, reading into it a bit more they are not just special strings. Somehow fish marks those variables as special list values. But as soon as you echo them they get concatenated with spaces.