bash -c "workon" return: "команда не найдена"

2993
elpddev

Использование "workon" в bash приводит к выводу списка в envs.

bash> workon project_1 

При попытке через bash -c возвращается ошибка.

bash> bash -c "workon" bash: workon: command not found 

Изменить 1: Больше информации по комментарию

bash> type workon  workon is a function workon ()  {  virtualenvwrapper_load; workon "$@" } 
2
В вопросе недостаточно информации. Что такое "работа"? `Тип Workon` должен сказать вам. Jakuje 8 лет назад 2
@Jakuje Спасибо за упоминание "типа". Я добавил информацию к вопросу. elpddev 8 лет назад 0

1 ответ на вопрос

0
Jakuje

workon is a function. Function definition is local for a shell and not visible in the subshells (same as variables definitions).

You need to export the function, if you want to have it visible in subshells. From manual page for bash:

export [-fn] [name[=word]] ...

export -p

The supplied names are marked for automatic export to the environment of subsequently executed commands. If the -f option is given, the names refer to functions. If no names are given, or if the -p option is supplied, a list of names of all exported variables is printed. The -n option causes the export property to be removed from each name. If a variable name is followed by =word, the value of the variable is set to word. export returns an exit status of 0 unless an invalid option is encountered, one of the names is not a valid shell variable name, or -f is supplied with a name that is not a function.

Therefore export -f workon after function definition will solve your problems.