Главная страница


ru.linux

 
 - RU.LINUX ---------------------------------------------------------------------
 From : Valentin Nechayev                    2:5020/400     02 Jun 2003  10:59:32
 To : Maxim Razin
 Subject : Re: [[b]a]sh, '$@' без кавычек --  признак ошибки
 -------------------------------------------------------------------------------- 
 
 >>> Maxim Razin wrote: 
 
  VN>> Посмотрел в SUSv3. Отмазались, гады:
  VN> >>4 arguments:
  VN>>           The results are unspecified.
 MR> Так что, -a и -o нельзя пользоваться?
 MR> Значит, придётся так:
 MR> if [ -r "$file" ]; then if [ -w "$file" ]; then
 MR>     echo "OK"
 MR> fi; fi
 MR> Это хоть переносимо?
 
 Опять же SUSv3:
 
 ==={{{
     APPLICATION USAGE
 
      Scripts should be careful when dealing with user-supplied input
      that could be confused with primaries and operators. Unless the
      application writer knows all the cases that produce input to the
      script, invocations like:
 test "$1" -a "$2"
 
      should be written as:
 test "$1" && test "$2"
 
      to avoid problems if a user supplied values such as $1 set to '!'
      and $2 set to the null string. That is, in cases where maximal
      portability is of concern, replace:
 test expr1 -a expr2
 
      with:
 test expr1 && test expr2
 
      and replace:
 test expr1 -o expr2
 
      with:
 test expr1 || test expr2
 
      but note that, in test, -a has higher precedence than -o while "&&"
      and "||" have equal precedence in the shell.
 
      Parentheses or braces can be used in the shell command language to
      effect grouping.
 
      Parentheses must be escaped when using sh; for example:
 test \( expr1 -a expr2 \) -o expr3
 
      This command is not always portable outside XSI-conformant systems.
      The following form can be used instead:
 ( test expr1 && test expr2 ) || test expr3
 
      The two commands:
 test "$1"
 test ! "$1"
 
      could not be used reliably on some historical systems. Unexpected
      results would occur if such a string expression were used and $1
      expanded to '!' , '(' , or a known unary primary. Better constructs
      are:
 test -n "$1"
 test -z "$1"
 
      respectively.
 
      Historical systems have also been unreliable given the common
      construct:
 test "$response" = "expected string"
 
      One of the following is a more reliable form:
 test "X$response" = "Xexpected string"
 test "expected string" = "$response"
 
      Note that the second form assumes that expected string could not be
      confused with any unary primary. If expected string starts with '-'
      , '(' , '!' , or even '=' , the first form should be used instead.
      Using the preceding rules without the XSI marked extensions, any of
      the three comparison forms is reliable, given any input. (However,
      note that the strings are quoted in all cases.)
 
      Because the string comparison binary primaries, '=' and "!=" , have
      a higher precedence than any unary primary in the greater than 4
      argument case, unexpected results can occur if arguments are not
      properly prepared. For example, in:
 test -d $1 -o -d $2
 
      If $1 evaluates to a possible directory name of '=' , the first
      three arguments are considered a string comparison, which shall
      cause a syntax error when the second -d is encountered. One of the
      following forms prevents this; the second is preferred:
 test \( -d "$1" \) -o \( -d "$2" \)
 test -d "$1" || test -d "$2"
 
      Also in the greater than 4 argument case:
 test "$1" = "bat" -a "$2" = "ball"
 
      syntax errors occur if $1 evaluates to '(' or '!' . One of the
      following forms prevents this; the third is preferred:
 test "X$1" = "Xbat" -a "X$2" = "Xball"
 test "$1" = "bat" && test "$2" = "ball"
 test "X$1" = "Xbat" && test "X$2" = "Xball"
 
 ===}}}
 
 В общем, херня творится. Hадо было префиксный синтаксис вводить, а не
 инфиксный.
 -netch-
 --- ifmail v.2.15dev5
  * Origin: Dark side of coredump (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Aleksey Cheusov   31 May 2003 20:49:29 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Valentin Nechayev   01 Jun 2003 10:47:36 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Maxim Razin   01 Jun 2003 12:37:38 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Valentin Nechayev   01 Jun 2003 20:09:11 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Valentin Nechayev   02 Jun 2003 07:36:52 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Maxim Razin   02 Jun 2003 08:56:14 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Valentin Nechayev   02 Jun 2003 10:59:32 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Maxim Razin   02 Jun 2003 22:55:38 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Aleksey Cheusov   03 Jun 2003 13:44:01 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Valentin Nechayev   03 Jun 2003 18:48:23 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Eugene B. Berdnikov   04 Jun 2003 17:03:09 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Andy Shevchenko   02 Jun 2003 21:10:46 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Michael de\'OZ   04 Jun 2003 18:57:24 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Aleksey Cheusov   02 Jun 2003 14:58:47 
 Re: [[b]a]sh, \'$@\' без кавычек -- признак ошибки   Valentin Nechayev   02 Jun 2003 15:11:03 
Архивное /ru.linux/11645d9847101.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional