
Okay, clickbait subject line, but hear me out. I had a bunch of files called *.sh for backing up stuff. I decided to use `run-parts` to run the entire folder of shell scripts at once. `run-parts` won't run *.sh files (?!?), they need to be *.s-h or something dumb. I wanted to REName *.sh -> *. In DOS: `ren *.sh *.` In bash, that will not work (with file globbing & pathname expansion enabled by default). I had to do this instead: for I in *.sh ; do mv ${I} ${I%%.sh} done Clearly, DOS > bash. (Told ya so, Hugh.) rb

| From: William Park via talk <talk@gtalug.org> | Ubuntu/Debian distros | will include 'rename' where you can use regex. So does Fedora. It is much more powerful that DOS's ren command. Even so, I so rarely use rename that I have to read the man page each time.

William Park via talk wrote on 2024-03-21 18:27:
for I in *.sh ; do mv ${I} ${I%%.sh} done
That will change 'x.sh' to 'x' without trailing dot.
Ubuntu/Debian distros will include 'rename' where you can use regex. How does `rename` (a Perl program, I believe?) handle globbing and
Exactly what's desired. pathname expansion? i.e. in a folder with 3 files: one.sh, two.sh, file.tar, typing: rename *.sh * means rename gets passed these parameters: one.sh two.sh one.sh two.sh file.tar I'd be curious how they handle that (I expect requiring params to be quoted). Thanks rb

'rename' from Ubuntu/Debian distro goes (from memory) rename 'perlexpr' files... where perlexpr is something like 's/x/y/'. 'rename' from util-linux package goes like rename 'pat' 'rep' files... On 2024-03-21 23:52, Ron / BCLUG via talk wrote:
William Park via talk wrote on 2024-03-21 18:27:
for I in *.sh ; do mv ${I} ${I%%.sh} done
That will change 'x.sh' to 'x' without trailing dot.
Exactly what's desired.
Ubuntu/Debian distros will include 'rename' where you can use regex. How does `rename` (a Perl program, I believe?) handle globbing and pathname expansion?
i.e. in a folder with 3 files: one.sh, two.sh, file.tar, typing:
rename *.sh *
means rename gets passed these parameters:
one.sh two.sh one.sh two.sh file.tar
I'd be curious how they handle that (I expect requiring params to be quoted).
Thanks
rb --- Post to this mailing list talk@gtalug.org Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk

| From: Ron / BCLUG via talk <talk@gtalug.org> | How does `rename` (a Perl program, I believe?) handle globbing and pathname | expansion? | | | i.e. in a folder with 3 files: one.sh, two.sh, file.tar, typing: | | rename *.sh * | | means rename gets passed these parameters: | | one.sh two.sh one.sh two.sh file.tar The DOS ren command is very simple. So too is the Unix Utilities one included in Fedora by default. rename [options] expression replacement file... The expression and replacement are simple strings, not patterns. There are options like --all and --last that affect where the expression can be matched. What you want is rename .sh '' *.sh which means for each filename matched by *.sh change every occurrence of ".sh" in its name to '' (empty) I think that regular expressions in at least "expression" would be nice. I'd often use ^ or $, to prevent surprises. So the perl-based version might be more useful. But I so rarely use rename that I have to read the man page each time. Once or twice a year.

D. Hugh Redelmeier wrote on 2024-03-22 06:56:
What you want is rename .sh '' *.sh which means for each filename matched by *.sh change every occurrence of ".sh" in its name to '' (empty)
Ah, that's a clever idea - the glob at the end so that rename can grab the first two parameters and apply those to all the remaining params (list of files to operate on). Thanks rb
participants (3)
-
D. Hugh Redelmeier
-
Ron / BCLUG
-
William Park