0

!! This question is not about SHELL, it's about BASH, can't change the faulty tag !!

I've got a code that removes the spaces in directories and filenames (and inserts a dot);

find $jdir -depth -name "* *" -execdir rename 's/ /./g' "{}" \;

let's say $jdir = "test files are here"

This code don't rename the $jdir.

and I can't set it to the parent directory, because then it would rename a lot of other directories.

How do I get it to rename the $jdir?

(testing bug? in forum, disregard this line) I can't change the tags, a bug in the forum?

JoBe
  • 397
  • 5
  • 17
  • well, maybe, @Siva but I need change the first directory also, not all files and directories in that directory... – JoBe Aug 13 '20 at 17:51
  • @Kamil sorry for confusing you, this is about bash, not shell, the forum don't let me change the faulty shell-tag – JoBe Aug 13 '20 at 18:40
  • Bash is a shell. This answer explicitly mentions bash. Your code works for me, if only $jdir is properly double-quoted. – Kamil Maciorowski Aug 13 '20 at 18:42
  • @Kamil oh, thought shell and bash was two different shells.. well, newbies you know... but my code only fixes the files and directories inside $jdir, not the $jdir itself.. or does it do that for you? – JoBe Aug 13 '20 at 18:50
  • It does. The directory gets renamed to test.files.are.here. Ubuntu 18.04.4 LTS; find (GNU findutils) 4.7.0-git. – Kamil Maciorowski Aug 13 '20 at 18:53
  • @Kamil oh, found it.. it was actually both double-qoute and the end-slash that was messing it up! – JoBe Aug 13 '20 at 19:06
  • .. now I just need a way to get the new "main directory" to a variable, since the old one don't exist anymore.. got any suggestion? – JoBe Aug 13 '20 at 19:08
  • @JoBe jdir=${jdir// /.} would replace all spaces by dots in the value of the variable jdir. – Kusalananda Aug 13 '20 at 19:10
  • @Kusalananda thank you, that solved that issue! – JoBe Aug 13 '20 at 19:18

0 Answers0