How to set a global persistent variable?

Clash Royale CLAN TAG#URR8PPP up vote
2
down vote
favorite
I'm creating a bashscript to setup a small application I'm writing. Part of that setup requires setting an environment variable so that other processes may reference it.
My simple shell script test looks like this:
#!/bin/sh
export FOO=abc
I understand why FOO will not be visible after the script is executed, if done like so:
$ sh script.sh
and why this will make it visible:
$ source script.sh
so that's a workaround, but I'm wondering how common install scripts do this - for example, I'm pretty sure installers like mysql etc do set global environment variables.
What is the right way to do this? I guess I can ask my users to install by running:
$ source script.sh
but not sure if there is a better way.
Thanks
bash scripts environment-variables
add a comment |Â
up vote
2
down vote
favorite
I'm creating a bashscript to setup a small application I'm writing. Part of that setup requires setting an environment variable so that other processes may reference it.
My simple shell script test looks like this:
#!/bin/sh
export FOO=abc
I understand why FOO will not be visible after the script is executed, if done like so:
$ sh script.sh
and why this will make it visible:
$ source script.sh
so that's a workaround, but I'm wondering how common install scripts do this - for example, I'm pretty sure installers like mysql etc do set global environment variables.
What is the right way to do this? I guess I can ask my users to install by running:
$ source script.sh
but not sure if there is a better way.
Thanks
bash scripts environment-variables
Possible solutions: askubuntu.com/questions/58814/â¦
â Terrance
Mar 21 at 17:34
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm creating a bashscript to setup a small application I'm writing. Part of that setup requires setting an environment variable so that other processes may reference it.
My simple shell script test looks like this:
#!/bin/sh
export FOO=abc
I understand why FOO will not be visible after the script is executed, if done like so:
$ sh script.sh
and why this will make it visible:
$ source script.sh
so that's a workaround, but I'm wondering how common install scripts do this - for example, I'm pretty sure installers like mysql etc do set global environment variables.
What is the right way to do this? I guess I can ask my users to install by running:
$ source script.sh
but not sure if there is a better way.
Thanks
bash scripts environment-variables
I'm creating a bashscript to setup a small application I'm writing. Part of that setup requires setting an environment variable so that other processes may reference it.
My simple shell script test looks like this:
#!/bin/sh
export FOO=abc
I understand why FOO will not be visible after the script is executed, if done like so:
$ sh script.sh
and why this will make it visible:
$ source script.sh
so that's a workaround, but I'm wondering how common install scripts do this - for example, I'm pretty sure installers like mysql etc do set global environment variables.
What is the right way to do this? I guess I can ask my users to install by running:
$ source script.sh
but not sure if there is a better way.
Thanks
bash scripts environment-variables
bash scripts environment-variables
asked Mar 21 at 17:30
user3203425
1345
1345
Possible solutions: askubuntu.com/questions/58814/â¦
â Terrance
Mar 21 at 17:34
add a comment |Â
Possible solutions: askubuntu.com/questions/58814/â¦
â Terrance
Mar 21 at 17:34
Possible solutions: askubuntu.com/questions/58814/â¦
â Terrance
Mar 21 at 17:34
Possible solutions: askubuntu.com/questions/58814/â¦
â Terrance
Mar 21 at 17:34
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Add these lines to your script. Your script should have root access.
echo 'export FOO=abc' > /etc/profile.d/foo.sh
Next restart it will be available.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Add these lines to your script. Your script should have root access.
echo 'export FOO=abc' > /etc/profile.d/foo.sh
Next restart it will be available.
add a comment |Â
up vote
1
down vote
accepted
Add these lines to your script. Your script should have root access.
echo 'export FOO=abc' > /etc/profile.d/foo.sh
Next restart it will be available.
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Add these lines to your script. Your script should have root access.
echo 'export FOO=abc' > /etc/profile.d/foo.sh
Next restart it will be available.
Add these lines to your script. Your script should have root access.
echo 'export FOO=abc' > /etc/profile.d/foo.sh
Next restart it will be available.
answered Mar 21 at 17:40
dedunumax
4,26021526
4,26021526
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1018014%2fhow-to-set-a-global-persistent-variable%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Possible solutions: askubuntu.com/questions/58814/â¦
â Terrance
Mar 21 at 17:34