When writing a Bash script you can use brace expansion to quickly generate lists:
I'm hoping to be proven wrong here, but I don't believe there is a way to do it exactly like with bash, or with as few keystrokes.
You can iterate over the list by piping it through a foreach-object
to achieve the same result though.
1..5 | foreach-object { "test" + $_ }
Or using the shorthand:
1..5 | %{"test$_"}
In both cases (%
is an alias for foreach-object
), the output is:
test1
test2
test3
test4
test5
Note: if you're building this into a script for publishing/distribution/reuse, use the more verbose foreach-object
, not the shorthand %
- for readability.