* [Comm] test -d on directory with space in name
@ 2006-12-06 12:40 Vitaly Ostanin
2006-12-06 13:39 ` Alexey I. Froloff
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Vitaly Ostanin @ 2006-12-06 12:40 UTC (permalink / raw)
To: ALT Linux Community
[-- Attachment #1: Type: text/plain, Size: 515 bytes --]
Здравствуйте.
Скажите, где я тупой, а?
В этом скрипте не выполняется проверка [ -d "$FILE" ], если в
имени $FILE есть пробелы. В командной строке такая проверка
проходит успешно.
#!/bin/sh
do_du()
{
du -sbx * | sort -rn | while read f;
do
echo $f
FILE=`echo $f | cut -d ' ' -f2-`
if [ -d "$FILE" ]; then
echo "^^^dir^^^"
cd "$FILE"
do_du
fi
done
}
do_du
--
Regards, Vyt
mailto: vyt@vzljot.ru
JID: vyt@vzljot.ru
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Comm] test -d on directory with space in name
2006-12-06 12:40 [Comm] test -d on directory with space in name Vitaly Ostanin
@ 2006-12-06 13:39 ` Alexey I. Froloff
2006-12-06 14:47 ` Vitaly Ostanin
2006-12-06 14:17 ` A.Kitouwaykin
2006-12-06 23:53 ` Dmitry V. Levin
2 siblings, 1 reply; 8+ messages in thread
From: Alexey I. Froloff @ 2006-12-06 13:39 UTC (permalink / raw)
To: ALT Linux Community
[-- Attachment #1: Type: text/plain, Size: 341 bytes --]
* Vitaly Ostanin <vyt@> [061206 16:09]:
> FILE=`echo $f | cut -d ' ' -f2-`
FILE="`echo $f | cut -d ' ' -f2-`"
> if [ -d "$FILE" ]; then
--
Regards, Alexey I. Froloff
AIF5-RIPN, AIF5-RIPE
-------------------------------------------
Inform-Mobil, Ltd. System Administrator
http://www.inform-mobil.ru/
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Comm] test -d on directory with space in name
2006-12-06 12:40 [Comm] test -d on directory with space in name Vitaly Ostanin
2006-12-06 13:39 ` Alexey I. Froloff
@ 2006-12-06 14:17 ` A.Kitouwaykin
2006-12-06 23:53 ` Dmitry V. Levin
2 siblings, 0 replies; 8+ messages in thread
From: A.Kitouwaykin @ 2006-12-06 14:17 UTC (permalink / raw)
To: ALT Linux Community
On Wed, 06 Dec 2006 15:40:04 +0300
Vitaly Ostanin <vyt@vzljot.ru> wrote:
> du -sbx * | sort -rn | while read f;
+ du -sbx * | sort -rn | while read f FILE;
> do
> echo $f
> FILE=`echo $f | cut -d ' ' -f2-`
+ #FILE=`echo $f | cut -d ' ' -f2-`
?
--
Китайкин Анатолий Константинович
ОАО "Радиоавионика", СПб
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Comm] test -d on directory with space in name
2006-12-06 13:39 ` Alexey I. Froloff
@ 2006-12-06 14:47 ` Vitaly Ostanin
2006-12-07 6:51 ` Alexey I. Froloff
0 siblings, 1 reply; 8+ messages in thread
From: Vitaly Ostanin @ 2006-12-06 14:47 UTC (permalink / raw)
To: ALT Linux Community
[-- Attachment #1: Type: text/plain, Size: 290 bytes --]
Alexey I. Froloff пишет:
> * Vitaly Ostanin <vyt@> [061206 16:09]:
>> FILE=`echo $f | cut -d ' ' -f2-`
> FILE="`echo $f | cut -d ' ' -f2-`"
Пробовал, не помогает. У тебя так работает?
<skipped/>
--
Regards, Vyt
mailto: vyt@vzljot.ru
JID: vyt@vzljot.ru
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Comm] test -d on directory with space in name
2006-12-06 12:40 [Comm] test -d on directory with space in name Vitaly Ostanin
2006-12-06 13:39 ` Alexey I. Froloff
2006-12-06 14:17 ` A.Kitouwaykin
@ 2006-12-06 23:53 ` Dmitry V. Levin
2006-12-07 9:44 ` Fr. Br. George
2006-12-13 10:36 ` Vitaly Ostanin
2 siblings, 2 replies; 8+ messages in thread
From: Dmitry V. Levin @ 2006-12-06 23:53 UTC (permalink / raw)
To: ALT Linux Community
[-- Attachment #1: Type: text/plain, Size: 791 bytes --]
Hi,
On Wed, Dec 06, 2006 at 03:40:04PM +0300, Vitaly Ostanin wrote:
> Здравствуйте.
>
> Скажите, где я тупой, а?
Не все пробельные символы одинаковые.
> В этом скрипте не выполняется проверка [ -d "$FILE" ], если в
> имени $FILE есть пробелы.
Табуляция там, а не пробелы.
> #!/bin/sh
>
> do_du()
> {
> du -sbx * | sort -rn | while read f;
du -sbx * | sort -rn | while read size FILE;
> do
> echo $f
echo "$size $FILE"
> FILE=`echo $f | cut -d ' ' -f2-`
это не нужно
> if [ -d "$FILE" ]; then
> echo "^^^dir^^^"
> cd "$FILE"
> do_du
cd -
> fi
> done
> }
>
> do_du
Имейте в виду, этот скрипт нельзя запускать в недоверенных каталогах,
он там может заблудиться.
--
ldv
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Comm] test -d on directory with space in name
2006-12-06 14:47 ` Vitaly Ostanin
@ 2006-12-07 6:51 ` Alexey I. Froloff
0 siblings, 0 replies; 8+ messages in thread
From: Alexey I. Froloff @ 2006-12-07 6:51 UTC (permalink / raw)
To: ALT Linux Community
[-- Attachment #1: Type: text/plain, Size: 478 bytes --]
* Vitaly Ostanin <vyt@> [061206 17:52]:
> > * Vitaly Ostanin <vyt@> [061206 16:09]:
> >> FILE=`echo $f | cut -d ' ' -f2-`
> > FILE="`echo $f | cut -d ' ' -f2-`"
> Пробовал, не помогает. У тебя так работает?
Заработало, когда "cd .." добавил после рекурсивного вызова
do_du.
--
Regards, Alexey I. Froloff
AIF5-RIPN, AIF5-RIPE
-------------------------------------------
Inform-Mobil, Ltd. System Administrator
http://www.inform-mobil.ru/
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Comm] test -d on directory with space in name
2006-12-06 23:53 ` Dmitry V. Levin
@ 2006-12-07 9:44 ` Fr. Br. George
2006-12-13 10:36 ` Vitaly Ostanin
1 sibling, 0 replies; 8+ messages in thread
From: Fr. Br. George @ 2006-12-07 9:44 UTC (permalink / raw)
To: ALT Linux Community
On Thu, Dec 07, 2006 at 02:53:39AM +0300, Dmitry V. Levin wrote:
> Имейте в виду, этот скрипт нельзя запускать в недоверенных каталогах,
> он там может заблудиться.
То есть заходить в симлинки вместо каталогов.
А ещё выдавать ошибку на пустых каталогах и не заходить в скрытые.
И очень трудно понять, кто в кого был вложен.
ls -RsSk ? du -axb ? Вот с du -axb стоит, наверное, поиграть: обработать
какой-нибудь awk-ой один текст не в пример быстрее, чем многократно
запускать _рекурсивный_ du. На крайний случай -- совместно с
find . -type d, чтобы получить список каталогов.
--
Георгий Курячий (aka Fr. Br. George)
Руководитель образовательных проектов ALT Linux
mailto : george at altlinux_ru
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Comm] test -d on directory with space in name
2006-12-06 23:53 ` Dmitry V. Levin
2006-12-07 9:44 ` Fr. Br. George
@ 2006-12-13 10:36 ` Vitaly Ostanin
1 sibling, 0 replies; 8+ messages in thread
From: Vitaly Ostanin @ 2006-12-13 10:36 UTC (permalink / raw)
To: ALT Linux Community
[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]
Dmitry V. Levin пишет:
> Hi,
>
> On Wed, Dec 06, 2006 at 03:40:04PM +0300, Vitaly Ostanin wrote:
>> Здравствуйте.
>>
>> Скажите, где я тупой, а?
>
> Не все пробельные символы одинаковые.
>
>> В этом скрипте не выполняется проверка [ -d "$FILE" ], если в
>> имени $FILE есть пробелы.
>
> Табуляция там, а не пробелы.
На экране да, но почему тогда работает "cut -d ' '" ?
Вывод "du" не может меняться в зависимости от того, куда он
направлен? Такая мысль пришла в голову по аналогии с разницей
вывода "ls" (в несколько столбцов) и "ls | less" (в один столбец)
>> #!/bin/sh
>>
>> do_du()
>> {
>> du -sbx * | sort -rn | while read f;
> du -sbx * | sort -rn | while read size FILE;
Спасибо, про несколько name у read не знал. Можно адаптировать и так:
du -sbx0 * | sort -rnz | while read -d '\0' size FILE;
А затык был именно в "cd -", спасибо ещё раз.
>> do
>> echo $f
> echo "$size $FILE"
>> FILE=`echo $f | cut -d ' ' -f2-`
> это не нужно
>> if [ -d "$FILE" ]; then
>> echo "^^^dir^^^"
>> cd "$FILE"
>> do_du
> cd -
>> fi
>> done
>> }
>>
>> do_du
>
> Имейте в виду, этот скрипт нельзя запускать в недоверенных каталогах,
> он там может заблудиться.
Даже realpath не поможет?
<skipped/>
--
Regards, Vyt
mailto: vyt@vzljot.ru
JID: vyt@vzljot.ru
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-12-13 10:36 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-06 12:40 [Comm] test -d on directory with space in name Vitaly Ostanin
2006-12-06 13:39 ` Alexey I. Froloff
2006-12-06 14:47 ` Vitaly Ostanin
2006-12-07 6:51 ` Alexey I. Froloff
2006-12-06 14:17 ` A.Kitouwaykin
2006-12-06 23:53 ` Dmitry V. Levin
2006-12-07 9:44 ` Fr. Br. George
2006-12-13 10:36 ` Vitaly Ostanin
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git