Что означает первый "." значит в '. ~ / .bashrc '? [дубликат]

Я видел сообщение об исправлении ваш псевдоним в .bashrc .

И он говорит, что после того, как вы поместите свой псевдоним в .bashrc , вам нужно будет использовать:

. ~/.bashrc

Я не совсем понимаю, что здесь делает первая точка ('.'). Какова его функция и как она называется?

11
задан 8 October 2014 в 04:17

2 ответа

Интересный... имя, кажется, dot-command, в Вашем случае это включает .bashrc в программную оболочку вызова (в Вашем случае, Вашей среде удара). Как Вы называете его из командной строки, это обновляет Ваши переменные окружения, поскольку переменные установлены в .bashrc.

echo "FOO=bar" > test
echo $FOO

никакой результат, огибающая переменная не набор. Но после определения источника "тестового" файла:

. test

огибающее переменное НЕЧТО установлено и

echo $FOO

результат в выводе

bar

Я нашел следующую информацию здесь:

Определение источника файла (точечная команда) импортируют код в сценарий, добавление к сценарию (тот же эффект как #include директива в программе C). Конечный результат совпадает с, если "полученные" строки кода физически присутствовали в теле сценария. Это полезно в ситуациях, когда несколько сценариев используют файл общих данных или библиотеку функций.

Кроме того, посмотрите этот вопрос. В ударе, . совпадает с source.

5
ответ дан 8 October 2014 в 04:17

Если Вы хотите проверить что-то в удар, используйте type и man.

В Вашем случае Вы хотите знать то, что.

$ type .
. is a shell builtin

окружают встроенный, означает это . внутренний bash shell. Можно найти информацию об оболочке builtins в bash страница руководства. Существует большой раздел SHELL ВСТРОЕННЫЕ КОМАНДЫ

$ man bash

SHELL BUILTIN COMMANDS
       Unless otherwise noted, each builtin command documented in this section
       as accepting options preceded by - accepts -- to signify the end of the
       options.   The  :, true, false, and test builtins do not accept options
       and do not treat -- specially.  The exit, logout, break, continue, let,
       and  shift builtins accept and process arguments beginning with - with‐
       out requiring --.  Other builtins that accept  arguments  but  are  not
       specified  as accepting options interpret arguments beginning with - as
       invalid options and require -- to prevent this interpretation.
       : [arguments]
              No effect; the command does nothing beyond  expanding  arguments
              and  performing any specified redirections.  A zero exit code is
              returned.

        .  filename [arguments]
       source filename [arguments]
              Read and execute commands from filename  in  the  current  shell
              environment  and return the exit status of the last command exe‐
              cuted from filename.  If filename  does  not  contain  a  slash,
              filenames  in  PATH  are  used  to find the directory containing
              filename.  The file searched for in PATH need not be executable.
              When  bash  is  not  in  posix  mode,  the  current directory is
              searched if no file is found in PATH.  If the sourcepath  option
              to  the  shopt  builtin  command  is turned off, the PATH is not
              searched.  If any arguments are supplied, they become the  posi‐
              tional  parameters  when  filename  is  executed.  Otherwise the
              positional parameters are unchanged.  The return status  is  the
              status  of  the  last  command exited within the script (0 if no
              commands are executed), and false if filename is  not  found  or
              cannot be read.
20
ответ дан 8 October 2014 в 04:17

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

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