I want to split "-r --run"
into "-r"
and "--run"
for
string split " " "-r --run"
I get
string split: -r --run: unknown option` as an error
It is mistaking the string for flags. How do I make it treat it as a string to split?
The string
docs say:
Arguments beginning with
-
are normally interpreted as switches;--
causes the following arguments not to be treated as switches even if they begin with-
.
So the command is:
string split -- " " "-r --run"
--
convention for separating args from commands is very common: I'm surprised nobody suggested it earlier.
string split -- " " $s
May 21, 2023 at 21:21
--
before the separator, making it look more clear (so that the --
comes before all non-switch arguments).
Another way to do it would be:
echo "--r -run" | string split " "
So piping the string into that command.
$ man getopt
tells you.linux
tag, because fish is available for macOS, BSD and Windows as well (fishshell.com/#platform_tabs)