-1

I'm about to move some IMAP accounts to another server. The old server was setup to add the prefix .INBOX. to each folder, but not the new one . So I tried to rename all folders, stripping the .INBOX. prefixes.

What I did in bash:

for name in .INBOX.*;
do
newname="$(echo "$name" | cut -c8-)";
mv '$name' '$newname';
done

But this script did only rename such folders which didn't contain whitespaces. The ones with whitespaces lead into error messages.

What's the trick?

Frank
  • 3
  • 1

1 Answers1

0

Use quotation. In my example below I prefer to use while read

Example

$ ls -l *.txt
-rw-rw-r-- 1 ftpcpl ftpcpl 0 Jul 24 11:36 hello and goodbye.txt
-rw-rw-r-- 1 ftpcpl ftpcpl 0 Jul 24 11:36 hello.txt
$ echo "hello.txt" > lista.txt
$ echo "hello and goodbye.txt" >> lista.txt
$ more lista.txt
hello.txt
hello and goodbye.txt
$ while IFS= read -r file; do mv -- "$file" "$file".new ; done < lista.txt
$ ls -l *.new
-rw-rw-r-- 1 ftpcpl ftpcpl 0 Jul 24 11:36 hello and goodbye.txt.new
-rw-rw-r-- 1 ftpcpl ftpcpl 0 Jul 24 11:36 hello.txt.new
$
Roberto Hernandez
  • 8,231
  • 3
  • 14
  • 43
  • Thank you. The problem was the single quotes instead doubled ones. But your example will also do the job. – Frank Jul 24 '20 at 10:39