I have a need to pass a script to a perl script to run in some directories in linux (ubuntu) with bash –version
GNU bash, versión 4.4.20(1)-release (x86_64-redhat-linux-gnu)
These directories have a problem, and that is that they have extended characters including spaces, and local language characters.
IFS=$'n'
for dir in $(ls -1ld /home/setdart/mail/setdart.com/albertit/{.,?}*/ | tr 'n' '' | xargs -0 -n 1 basename); do echo "$dir"; done > albertit.txt
Which gives me
.Archive
cur
.Drafts
.Junk
.My Folders
.My Folders.Clients
.My Folders.Cuentas
.My Folders.Enric
.My Folders.Google
.My Folders.Prove&AO8-dors
.My Folders.Prove&AO8-dors.Abdul
.My Folders.Prove&AO8-dors.Abdul.Dominis
.My Folders.Prove&AO8-dors.Datax
.My Folders.Prove&AO8-dors.DeepL
.My Folders.Prove&AO8-dors.Gerard Cuenca
.My Folders.Prove&AO8-dors.Lloguer iMacs
.My Folders.Prove&AO8-dors.Movistar - Mabel Serrano
.My Folders.Prove&AO8-dors.Vadim
.My Folders.Prove&AO8-dors.Xavi Navarro
.My Folders.Scott
.My Folders.Scott.20220224 Errores facturas pdf
.My Folders.Setdart
.My Folders.Setdart.Admin y Conta
.My Folders.Setdart.Admin y Conta.202203 Quotation errors
.My Folders.Setdart.Ident Clientes
.My Folders.Setdart.Log&AO0-stica
.My Folders.Setdart.Lotes entregados no pagados
.My Folders.Setdart.M Pal&AOg-s
.My Folders.Setdart.Madrid
.My Folders.Setdart.Ramon
.My Folders.Setdart.Tasaciones
.My Folders.Software
.My Folders.Spam etc
.My Folders.Tests
.My Folders.Tests.E-mails Setdart
.My Folders.Tests.Reclamaciones
.My Folders.Tests.Reclamaciones.V1
.My Folders.Tests.Reclamaciones.V2
.My Folders.Tests.Recuperar codi d'usuari i contrasenya
.My Folders.Tests.Recuperar codi d'usuari i contrasenya.V1
.My Folders.Tests.Recuperar codi d'usuari i contrasenya.V2
.My Folders.Todoist
.My Folders.TPV
.My Folders.Varis
.My Folders.Web
new
.Sent
.spam
tmp
.Trash
Files containing &AO8
, &AO0-
are not processed by the second command, they are actually extended characters of the language
for file in $(cat albertit.txt); do echo "$file"; tools/maildir-size-fix.pl -a -f -c -r $file; done
I can’t find a solution and I have more than 100 users in whom I have to pass the script and all of them, being Catalan, use Catalan as the language to name their folders.
I don’t know how to proceed to do it.
2
Answers
for i in $(..)
is an antipattern. https://mywiki.wooledge.org/BashFAQ/001for i in $(command); do echo $i
Just execute the command, why loop with echo. It already echoes.| tr ' ' 'n' | xargs -0
does not add any security. Just| xargs -d 'n'
then, newlines are going to hurt anyway.I could see something along:
Or I think just:
And then:
But then just:
Generally, the simple construct of
really should work, even with odd characters.
Does it not? Did you quote it?
If it doesn’t, what does it do?