« first day (1304 days earlier)      last day (1749 days later) » 

3:57 AM
@Queen f but VTC as GMTC / library req
@Queen k Ed Morton
@Queen k
 
4:17 AM
Hey. I'm a bit of a noob at writing bash scripts. I'm trying to make a git pre-commit script which renames every .git folder found in a subfolder to .xgit.

I've got some of the pieces together (I think), but I don't really understand some of these functions.

Here's what I have
find **/ -name .git -print0 | xargs -0 sed -i 's/git/xgit/' | xargs -0 echo
And if you're not into it, no worries
 
@Queen k
 
Found something for my problem:

https://stackoverflow.com/a/245854/4808079
for x in $(find . -name \*.html); do
mv $x $(echo "$x" | sed 's/\.html$/.htm/')
done
 
@SephReed echo doesn't do anything useful here, to mv you need to output both the old and the new name
 
oh, echo was for testing
just to see what I'd get, before adding the mv
 
4:28 AM
@SephReed you need to quote things, this will break if you have weird file names
 
I've got it working. Here's my code:

```
for x in $(find */ -name .git); do
mv $x $(echo "$x" | sed 's/\.git$/.xgit/')
done
```
 
find . -name '*.html' -exec sh -c 'for f; do mv "$f" "${f.html}.htm"; done' _
@SephReed still need the quoting fixes
 
It always blows my mind how many ways there are to do this.

I've tested the code above and it works. Is this an OS thing?
 
and with a parameter expansion you can avoid the fugly echo | sed in a subprocess
@SephReed as always, unquoted file names work fine with trivial file names, but your code should cope with nontrivial ones
some people like to create a directory with funny file names with newlines, single quotes, irregular spacing etc in their names just to have something to test on
 
I'm only ever going to be doing .git <-> xgit, but I'm still very interested.
 
4:31 AM
so if the command is literally mv .git .xgit then there are no metacharacters which need quoting
but then probably you can find a rename tool which does this with no programming
 
The example you showed says find every file of name *.html starting at current dir ".", then execute a shell command from a string (-c), and that command does for each filename mv the file to... ("${f.html}.htm") I assume this is some form of bash replace. Then done.
is -exec part of find?
nvm. looked at man, it is.
 
5:05 AM
"some form of bash replace" is called parameter expansion
but I had a typo, it should be ${f%.html}
 
thank you @tripleee
 
5:22 AM
sure, sorry for being in and out of here repeatedly, I was called off to other things
 
no worries
 
 
7 hours later…
12:28 PM
@Queen k
 

« first day (1304 days earlier)      last day (1749 days later) »