How to define script shell variable to have scope outside script

I am using Ubuntu Natty.

I have a shell script that I saved in /etc/init.d/qstart. The shell script contains the following:

apt-get -y update
apt-get -y upgrade
apt-get -y install tofrodos gcc make nmap lsof expect sysstat
dbpass="mydbpassword"

However, after running the script, I want to verify that dbpass is installed, and enter echo $dbpassat the prompt. But it is empty.

How to define a variable in my shell script so that I can access it outside it ?!

Thanks in advance.

+5
source share
2 answers

You cannot set variables in the parent environment of a process. You can only set the current process environment or prepare the environment for your process children.

, script , . :

source your_script.sh

. your_script.sh

( ). your_script.sh , , script, .

, , script, , , , . , script - , . , (, - /var).

, , , . . , bash /etc/profile script $HOME/.bash_profile ( $HOME/.bash_login $HOME/.profile) script. . bash - . , .

+8

. , , source script.sh . script.sh , bash, .

, , ​​ init script , /etc/default/something, . , , source bashrc /etc/profile.d/something.

+2

All Articles