Re:Renaming files with mv without typing the name two times
by jraph on Monday April 13, 2020 @06:07PM
(#22860722)
Wow, I had not realized that one could compute Cartesian products using a shell.
[ Parent
| on HN ]
Re:Renaming files with mv without typing the name two times
by foobarian on Monday April 13, 2020 @06:21PM
(#22860840)
On the topic of things you didn't know the shell did: I found out about sequences recently and love them:
$ echo {0..19}
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ echo {00..19}
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
Re:Renaming files with mv without typing the name two times
by pkaye on Monday April 13, 2020 @06:29PM
(#22860904)
Looks like it also works with single letters.
$echo {A..D}
A B C D
Re:Renaming files with mv without typing the name two times
by smcameron on Monday April 13, 2020 @09:12PM
(#22861860)
Hmm, I'd always used the "seq" command for that...
$ echo `seq 0 19`
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Re:Renaming files with mv without typing the name two times
by perlwle on Tuesday April 14, 2020 @10:48AM
(#22866657)
Perl is very much like this too.
$ perl -le 'print join(" ", "00".."20")' 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
Re:Renaming files with mv without typing the name two times
by m463 on Tuesday April 14, 2020 @08:14AM
(#22864927)
wow, genius!
(the second doesn't work on older versions of bash, like macos)
Re:Renaming files with mv without typing the name two times
by mehrdadn on Monday April 13, 2020 @09:07PM
(#22861836)
Well, using Bash. A lot of these tricks aren't portable so you'll have fun when your scripts break on e.g. Dash (Ubuntu).
Re:Renaming files with mv without typing the name two times
by jraph on Tuesday April 14, 2020 @02:03AM
(#22863144)
Also works on zsh and fish, though fish does not enumerate in the same order. Indeed does not work on sh.
Thanks for the heads up.
Too bad it's not portable, but I guess this is mainly useful in an interactive shell.
I mostly use #!/usr/bin/env sh, so my scripts will remain free of shell Cartesian products and other brace expansions.