Shell error by file names with spaces

Vom einfachen Programm zum fertigen Debian-Paket, Fragen rund um Programmiersprachen, Scripting und Lizenzierung.
Antworten
gamma
Beiträge: 6
Registriert: 20.06.2006 12:24:18

Shell error by file names with spaces

Beitrag von gamma » 17.03.2008 13:05:06

Hallo,
I want to copy files, which Names have spaces. For example:

Code: Alles auswählen

$ ls t*
titel mitn(2) vonKk.txt 
When I use "find", I got the file name separately, like that:

Code: Alles auswählen

$ for i in $( find . -type f -mmin -200 ); do echo $i; done
./titel
mitn(2)
vonKk.txt
$
How can I get the correct name?

Thanks a lot for your answers?

[/quote]

Benutzeravatar
mistersixt
Beiträge: 6601
Registriert: 24.09.2003 14:33:25
Lizenz eigener Beiträge: GNU Free Documentation License

Beitrag von mistersixt » 17.03.2008 13:09:08

Set the IFS (see man page "bash") to something else than the default values, for example:

Code: Alles auswählen

mars:/tmp# touch "this is a test.txt"
mars:/tmp# ls -l this*
-rw-r--r-- 1 root root 0 2008-03-17 13:09 this is a test.txt
mars:/tmp# for i in $( find . -type f -name "this*" ); do echo $i; done 
./this
is
a
test.txt
mars:/tmp# IFS=";"
mars:/tmp# for i in $( find . -type f -name "this*" ); do echo $i; done 
./this is a test.txt
mars:/tmp#
There are probably other ways, too, this is just an example.

Regards, Joerg.
--
System: Debian Bookworm, 6.11.x.-x-amd64, ext4, AMD Ryzen 7 3700X, 8 x 3.8 Ghz., Radeon RX 5700 XT, 32 GB Ram, XFCE

gamma
Beiträge: 6
Registriert: 20.06.2006 12:24:18

Beitrag von gamma » 18.03.2008 10:41:12

Thanks Joerg, your tip is which I needed. I have tried to find a solution during more than 4 hours. I tried all, for example I tried with

Code: Alles auswählen

IFS="\n".
but this doesn't work when the file name has "n" .
I saw too, that the option -exec from "find" may be useful.

Thanks, again
Jorge

Benutzeravatar
hupfdule
Beiträge: 1864
Registriert: 09.12.2002 15:04:37
Wohnort: Berlin
Kontaktdaten:

Beitrag von hupfdule » 18.03.2008 11:02:40

Mist, ich glaub ich hab in meinem Profil aus Versehen die Forumsprache umgestellt.....

Antworten