Eu tenho um arquivo bash src-useful.bash, contendo funções úteis como say_hello(), localizadas em / path / to / useful.
No meu ~/.bash_profileeu adicionei as seguintes linhas:
export BASH_USEFUL=/path/to/useful
source $BASH_USEFUL/src-useful.bash
Abrindo um novo terminal, posso verificar o seguinte:
$ echo $BASH_USEFUL
/path/to/useful
$ cat $BASH_USEFUL/src-useful.bash
function hello() {
echo "hello!"
}
$ hello
hello!
Eu criei um script say_hello.sh:
$ cat say_hello.sh
echo "BASH_USEFUL: $BASH_USEFUL"
hello
$ ./say_hello.sh
BASH_USEFUL: /path/to/useful # Recognizsed
say_hello.sh: line 2: say_hello: command not found # Not recognized?
Se eu source $BASH_USEFUL/src-useful.bashem say_hello.shque vai funcionar no entanto:
$ cat say_hello.sh
echo "BASH_USEFUL: $BASH_USEFUL"
source $BASH_USEFUL/src-useful
say_hello
$ ./say_hello.sh
BASH_USEFUL: /path/to/useful # Recognized
hello! # Function say_hello is now recognized
Gostaria de saber por que a variável BASH_USEFULainda é reconhecida pelo meu script, enquanto as funções do meu arquivo de origem não podem ser vistas no ambiente pelo meu script em execução. Existe uma solução alternativa, além de fornecer meus src-useful.bashem meus scripts? Gostaria que src-useful.bashas funções fossem carregadas no ambiente de qualquer script iniciado.
hello()parasay_hello()nas etapas acima ...