[devel] glibc: обработка пустых подстрок в PATH, LD_PRELOAD etc

Dmitry V. Levin =?iso-8859-1?q?ldv_=CE=C1_altlinux=2Eorg?=
Сб Мар 29 04:03:05 MSK 2008


On Thu, Mar 27, 2008 at 01:26:42PM +0300, Konstantin S. Uvarin wrote:
>   Давно не дает мне покоя один вопрос: для чего glibc интерпретирует пустую 
> подстроку в $PATH, $LD_PRELOAD и т.п. как текущий каталог? Ведь если 
> пользователю нужно именно текущий каталог указать, он и укажет PATH=$PATH:.

Это требование стандарта (legacy feature).
Привожу цитату из SUSv3 про $PATH полностью (жаль, что вы её не нашли раньше):

"This variable shall represent the sequence of path prefixes that certain
functions and utilities apply in searching for an executable file known
only by a filename.  The prefixes shall be separated by a colon ( ':' ).
When a non-zero-length prefix is applied to this filename, a slash shall
be inserted between the prefix and the filename.  A zero-length prefix is
a legacy feature that indicates the current working directory.	It appears
as two adjacent colons ( "::" ), as an initial colon preceding the rest
of the list, or as a trailing colon following the rest of the list.
A strictly conforming application shall use an actual pathname (such
as .) to represent the current working directory in PATH .  The list
shall be searched from beginning to end, applying the filename to each
prefix, until an executable file with the specified name and appropriate
execution permissions is found.  If the pathname being sought contains
a slash, the search through the path prefixes shall not be performed.
If the pathname begins with a slash, the specified path is resolved
(see Pathname Resolution).  If PATH is unset or is set to null, the path
search is implementation-defined."

>   А так получается, что команда PATH=$PATH:$SOMEVAR делает не то, что 
> задумывалось, если SOMEVAR неопределена. 

Тогда пишите правильно, например,
PATH="$PATH${SOMEVAR:+:$SOMEVAR}"


-- 
ldv
----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя     : =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Тип     : application/pgp-signature
Размер  : 197 байтов
Описание: =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Url     : <http://lists.altlinux.org/pipermail/devel/attachments/20080329/03f180d7/attachment-0002.bin>


Подробная информация о списке рассылки Devel