Sample Header Ad - 728x90

How to make mv work with exotic directory names?

0 votes
1 answer
99 views
I created several scripts to move messages tagged via notmuch notmuch between Maildir directories. Having multiple accounts, I have some issues with the names of some directories mbsync created when syncing with gmail. Here is my typical Maildir structure for gmail accounts:
gmail-user2
├── [Gmail]
│   ├── Brouillons
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Corbeille
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Messages envoy&AOk-s
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   ├── Spam
│   │   ├── cur
│   │   ├── new
│   │   └── tmp
│   └── Tous les messages
│       ├── cur
│       ├── new
│       └── tmp
└── Inbox
    ├── cur
    ├── new
    └── tmp
When I run the following script:
function safeMove { s=${1##*/}; s=${s%%,*}; mv -f $1 $2/$s; }
echo Moving $(notmuch count --output=files tag:trash and tag:gmail-user2 and not path:/.*/Corbeille/ and not path:/.*/Trash/) trash-tagged mails to gmail-user2 Trash folder
for i in $(notmuch search --output=files tag:trash and tag:gmail-user2 and not path:/.*/Corbeille/ and not path:/.*/Trash/); do
    safeMove $i ~/Maildir/gmail-user2/[Gmail]/Corbeille/cur
done
I have the following error:
mv: cannot stat '/home/user1/Maildir/gmail-user2/[Gmail]/Tous': No such file or directory
mv: cannot stat 'les': No such file or directory
How could I make mv find the Tous les messages directory? EDIT: According to the links provided in the comments I added double quotes:
function safeMove { s=${1##*/}; s=${s%%,*}; mv -f $1 $2/$s; }
for i in "$(notmuch search --output=files tag:trash and tag:gmail-user2 and not path:/.*/Corbeille/ and not path:/.*/Trash/)"; do
    safeMove "$i" ~/Maildir/gmail-user2/[Gmail]/Corbeille/cur
done
Now I have the following error:
mv: target '/home/user1/Maildir/gmail-user2/[Gmail]/Corbeille/cur/1715687008.294831_40.user1-um450': No such file or directory
When find ~/Maildir/ -name 1715687008.294831_40.user1* gives:
/home/user1/Maildir/gmail-user2/[Gmail]/Tous les messages/cur/1715687008.294831_40.user1-um450,U=40:2,FS
Asked by crocefisso (193 rep)
May 15, 2024, 08:37 PM
Last activity: May 16, 2024, 10:56 AM