LINUX.ORG.RU

помогите разобраться

 


0

1
[user@fedora_22 ~]$ augpath=":$PATH:"
[user@fedora_22 ~]$ augdir=":/usr/bin:"
[user@fedora_22 ~]$ test "$augpath" != "${augpath/$augdir}" && echo Found || echo NotFound

An easy way to see if a directory is already on your path is to wrap both the directory name and the PATH variable with a leading and trailing colon (:) and test whether the delimited directory name is part of the delimited PATH. If you don’t delimit in this way, you might be testing for /bin and actually find /usr/bin, which contains the string /bin. Use shell brace expansion to remove a string from a parameter and then compare the result with the original. Listing 27 shows the basic constructs you could use. - поясняющий текст

"${augpath/$augdir}"

выяснил что удаляет из вывода :/usr/bin/: Не могу понять каким образом.Почему $ перед {. Как вообще это работает



Последнее исправление: tooncheg (всего исправлений: 2)

man bash

${parameter/pattern/string}
       Pattern substitution. [...]
       If string is null, matches of pattern are deleted and the / following
       pattern may be omitted. [...]
Т.е.

"${augpath/$augdir}"

эквивалентно

"${augpath/$augdir/}"

и оно заменяет :/usr/bin: пустой строкой.

P.S. Теги надо ставить тематические, а не бессмысленные вроде «help».

xaizek ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.