I often write ad-hoc loops straight into the command-line to run a bunch of experiments. It's always a one-time thing, so writing a script file for it is unwanted overhead.
Often, though, I'd like to zip over a bunch of parameters, I would like to run a command somewhat like the following:
for arg1,arg2 in 256,lol 128,foo 32,bar ./bla --many-flags --name $arg2 --something $arg1end
I can achieve something similar but quite brittle in fish with string
(or tr delim \n
in old versions) like so:
for exp in 256,lol 128,foo 32,bar ./bla --many-flags --name (string split ',' $exp)[2] --flag (string split ',' $exp)[1]end
I'm wondering of anyone knows of better ways which don't require the cumbersome sub-command for each use of an argument (an argument may even be used multiple times), and even worse, the arbitrary delimiter which can cause all sorts of problems?
Ideally, I could even use it as a let
like so:
for arg1,arg2 in 256,lol ./bla --many-flags --ame $arg2 --something $arg1end