У меня сложилось впечатление, что source
был синонимом для .
в bash. Однако, похоже, что в файле .profile
source
не работает. Это видео на YouTube демонстрирует, что когда source
используется в ~/.profile
для получения файла foo
, переменная, определенная в этом файле, не экспортируется в последующие оболочки. Однако, если вместо этого файл получен с использованием .
, переменная экспортируется, как и ожидалось.
Обратите внимание, что когда я использую source
, переменная окружения НЕ экспортируется, но когда я использую .
, она делает.
Они - точно то же, как объяснено в man bash
:
. 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 executed
from filename. If filename does not contain a slash, file names 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 argu‐ ments are supplied, they
become the positional 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.
проблема здесь - то, что source
удар вещь, стандарт на самом деле .
. Ваш .profile
только читается оболочками входа в систему и некоторыми (не все) менеджеры по входу в систему. Однако менеджеры по входу в систему (такие как lightdm) попытаются считать (источник) файл с помощью оболочки системы по умолчанию, обычно /bin/sh
. В Debian-полученных системах, /bin/sh
символьная ссылка на /bin/dash
, и dash
очень простая, совместимая POSIX оболочка, которая является не bash
и не знает о source
ключевое слово.
Поэтому команда проигнорирована, файл не получен, и переменная не определяется. Проиллюстрировать:
$ cat foo
myvar='foo1'
$ source foo
$ echo $myvar
foo1
то же самое в [1 113]:
$ echo [112]
dash
$ source foo
dash: 11: source: not found
$ . ~/foo ## dash needs the full path
$ echo $myvar
foo1