'How can I sort an array randomly in Fish Shell?

I have an array of strings, I want to shuffle the order of the strings.

I found this question but it deals with bash and I'm using fish shell. Is there a way to achieve this?



Solution 1:[1]

Using shuf as with the Bash version, it's a lot cleaner in Fish:

Using $PATH as an example, since it's a preexisting array of strings:

shuf -e (string collect $PATH)
# or
set random_path (shuf -e (string collect $PATH))

The variable assignment assumes that there are no newlines in the existing array elements.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NotTheDr01ds