Что означают эти символы «$ @»> / dev / null 2> & 1 "после команды? [Дубликат]

Я недавно нашел здесь решение моей проблемы, но я не могу полностью понять, что означает все в этой команде:

xdg-open "$@">/dev/null 2>&1
12
задан 26 July 2018 в 11:34

2 ответа

"$@"

"$@" эквивалентно "$1" "$2" ... (позиционные параметры к команде, хорошей для использования, когда существуют специальные символы, например, располагают с интервалами в параметрах).

От man bash:

   Special Parameters
       The shell treats several parameters specially.  These parameters may  only
       be referenced; assignment to them is not allowed.
       *      Expands  to the positional parameters, starting from one.  When the
              expansion is not within double quotes,  each  positional  parameter
              expands  to  a  separate  word.  In contexts where it is performed,
              those words are subject to  further  word  splitting  and  pathname
              expansion.   When  the  expansion  occurs  within double quotes, it
              expands to a single word with the value of each parameter separated
              by  the first character of the IFS special variable.  That is, "$*"
              is equivalent to "$1c$2c...", where c is the first character of the
              value  of  the  IFS  variable.  If IFS is unset, the parameters are
              separated by spaces.  If IFS is null,  the  parameters  are  joined
              without intervening separators.
       @      Expands  to the positional parameters, starting from one.  When the
              expansion occurs within double quotes, each parameter expands to  a
              separate  word.   That  is, "$@" is equivalent to "$1" "$2" ...  If
              the double-quoted expansion occurs within a word, the expansion  of
              the first parameter is joined with the beginning part of the origi‐
              nal word, and the expansion of the last parameter  is  joined  with
              the  last  part of the original word.  When there are no positional
              parameters, "$@" and $@ expand to nothing (i.e., they are removed).

>

Перенаправление стандартного вывода в файл

/dev/null

Специальный файл, который означает, что вывод нигде не будет перенаправлен, другими словами, не записанный нигде.

Посмотрите man null для получения дополнительной информации.

2>

Перенаправление вывода ошибок в файл

2> &1

Перенаправление вывода ошибок к стандартному выводу

От man bash:

   Note that the order of redirections is significant.  For example, the com‐
   mand

          ls > dirlist 2>&1

   directs both standard output and standard error to the file dirlist, while
   the command

          ls 2>&1 > dirlist

   directs only the standard output to file  dirlist,  because  the  standard
   error  was  duplicated from the standard output before the standard output
   was redirected to dirlist.
22
ответ дан 23 November 2019 в 03:31
  • "$@": все аргументы сценария или вызова функции.
  • >: перенаправление средств stdout (то же как 1>).
  • >/dev/null: перенаправление средств stdout кому: /dev/null, значение просто повреждает вывод.
  • 2>&1 Перенаправьте errout (2>) к stdout (&1).
6
ответ дан 23 November 2019 в 03:31

Другие вопросы по тегам:

Похожие вопросы: