Prompt for User Input and turn it into an environment variableEnvironment variable vs Shell variable, what's the difference?Setting global environment variable for everyoneEnvironment Variable - how does properly set them (bashrc or profile)Why can't my user see environment variable?environment variable not workingEnvironment Variable for PYTHONPATHcapturing current user in variable and inserting it into fileANDROID_HOME environment variableEnvironment variableHow to find the source definition of an environment variable?
Why airport relocation isn't done gradually?
What happens when a metallic dragon and a chromatic dragon mate?
Email Account under attack (really) - anything I can do?
Does bootstrapped regression allow for inference?
If a centaur druid Wild Shapes into a Giant Elk, do their Charge features stack?
Can I legally use front facing blue light in the UK?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
What is the command to reset a PC without deleting any files
Where to refill my bottle in India?
Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?
Are cabin dividers used to "hide" the flex of the airplane?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Is domain driven design an anti-SQL pattern?
What causes the sudden spool-up sound from an F-16 when enabling afterburner?
Is every set a filtered colimit of finite sets?
Is "plugging out" electronic devices an American expression?
Where else does the Shulchan Aruch quote an authority by name?
Doomsday-clock for my fantasy planet
How to manage monthly salary
Is there any use for defining additional entity types in a SOQL FROM clause?
Why is the design of haulage companies so “special”?
How could a lack of term limits lead to a "dictatorship?"
Can a planet have a different gravitational pull depending on its location in orbit around its sun?
Why doesn't a const reference extend the life of a temporary object passed via a function?
Prompt for User Input and turn it into an environment variable
Environment variable vs Shell variable, what's the difference?Setting global environment variable for everyoneEnvironment Variable - how does properly set them (bashrc or profile)Why can't my user see environment variable?environment variable not workingEnvironment Variable for PYTHONPATHcapturing current user in variable and inserting it into fileANDROID_HOME environment variableEnvironment variableHow to find the source definition of an environment variable?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to make a script that gives me my current public IP, and asks the user for a new IP that should be declared as an environment variable for ubuntu, however even tho the MASTER variable is working as intended the SLAVE one isn't. here's a minimum sample of my script
#!/bin/bash
echo $SHELLOPTS
set -o allexport #All variables are auto set to export
MASTER=`ip addr | grep inet | grep 10. | tail -1 | sed 's/^ *//g' | cut -d ' ' -f 2 | sed 's//.*$//g'`
echo Master IP is: $MASTER
echo Insert the new IP:
read input
SLAVE=$input
echo Master IP is: $MASTER
echo Slave IP is: $SLAVE
Even tho the variable is actually printed, it cannot be reused more than once as an environment variable, I have been looking around this problem with no luck, any help will be really appreciated
command-line bash environment-variables
New contributor
add a comment |
I'm trying to make a script that gives me my current public IP, and asks the user for a new IP that should be declared as an environment variable for ubuntu, however even tho the MASTER variable is working as intended the SLAVE one isn't. here's a minimum sample of my script
#!/bin/bash
echo $SHELLOPTS
set -o allexport #All variables are auto set to export
MASTER=`ip addr | grep inet | grep 10. | tail -1 | sed 's/^ *//g' | cut -d ' ' -f 2 | sed 's//.*$//g'`
echo Master IP is: $MASTER
echo Insert the new IP:
read input
SLAVE=$input
echo Master IP is: $MASTER
echo Slave IP is: $SLAVE
Even tho the variable is actually printed, it cannot be reused more than once as an environment variable, I have been looking around this problem with no luck, any help will be really appreciated
command-line bash environment-variables
New contributor
3
If you want the shell variables to continue to exist after the script has finished, you need to source the script, like. scriptname
. If you execute it rather than source it, it is run in a subshell and all environmental changes are lost when the subshell exits.
– John1024
4 hours ago
Or dont use a script at all but a function defined in .bashrc
– Sergiy Kolodyazhnyy
4 hours ago
add a comment |
I'm trying to make a script that gives me my current public IP, and asks the user for a new IP that should be declared as an environment variable for ubuntu, however even tho the MASTER variable is working as intended the SLAVE one isn't. here's a minimum sample of my script
#!/bin/bash
echo $SHELLOPTS
set -o allexport #All variables are auto set to export
MASTER=`ip addr | grep inet | grep 10. | tail -1 | sed 's/^ *//g' | cut -d ' ' -f 2 | sed 's//.*$//g'`
echo Master IP is: $MASTER
echo Insert the new IP:
read input
SLAVE=$input
echo Master IP is: $MASTER
echo Slave IP is: $SLAVE
Even tho the variable is actually printed, it cannot be reused more than once as an environment variable, I have been looking around this problem with no luck, any help will be really appreciated
command-line bash environment-variables
New contributor
I'm trying to make a script that gives me my current public IP, and asks the user for a new IP that should be declared as an environment variable for ubuntu, however even tho the MASTER variable is working as intended the SLAVE one isn't. here's a minimum sample of my script
#!/bin/bash
echo $SHELLOPTS
set -o allexport #All variables are auto set to export
MASTER=`ip addr | grep inet | grep 10. | tail -1 | sed 's/^ *//g' | cut -d ' ' -f 2 | sed 's//.*$//g'`
echo Master IP is: $MASTER
echo Insert the new IP:
read input
SLAVE=$input
echo Master IP is: $MASTER
echo Slave IP is: $SLAVE
Even tho the variable is actually printed, it cannot be reused more than once as an environment variable, I have been looking around this problem with no luck, any help will be really appreciated
command-line bash environment-variables
command-line bash environment-variables
New contributor
New contributor
New contributor
asked 5 hours ago
GoatZeroGoatZero
1011
1011
New contributor
New contributor
3
If you want the shell variables to continue to exist after the script has finished, you need to source the script, like. scriptname
. If you execute it rather than source it, it is run in a subshell and all environmental changes are lost when the subshell exits.
– John1024
4 hours ago
Or dont use a script at all but a function defined in .bashrc
– Sergiy Kolodyazhnyy
4 hours ago
add a comment |
3
If you want the shell variables to continue to exist after the script has finished, you need to source the script, like. scriptname
. If you execute it rather than source it, it is run in a subshell and all environmental changes are lost when the subshell exits.
– John1024
4 hours ago
Or dont use a script at all but a function defined in .bashrc
– Sergiy Kolodyazhnyy
4 hours ago
3
3
If you want the shell variables to continue to exist after the script has finished, you need to source the script, like
. scriptname
. If you execute it rather than source it, it is run in a subshell and all environmental changes are lost when the subshell exits.– John1024
4 hours ago
If you want the shell variables to continue to exist after the script has finished, you need to source the script, like
. scriptname
. If you execute it rather than source it, it is run in a subshell and all environmental changes are lost when the subshell exits.– John1024
4 hours ago
Or dont use a script at all but a function defined in .bashrc
– Sergiy Kolodyazhnyy
4 hours ago
Or dont use a script at all but a function defined in .bashrc
– Sergiy Kolodyazhnyy
4 hours ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
GoatZero is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1132286%2fprompt-for-user-input-and-turn-it-into-an-environment-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
GoatZero is a new contributor. Be nice, and check out our Code of Conduct.
GoatZero is a new contributor. Be nice, and check out our Code of Conduct.
GoatZero is a new contributor. Be nice, and check out our Code of Conduct.
GoatZero is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1132286%2fprompt-for-user-input-and-turn-it-into-an-environment-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
If you want the shell variables to continue to exist after the script has finished, you need to source the script, like
. scriptname
. If you execute it rather than source it, it is run in a subshell and all environmental changes are lost when the subshell exits.– John1024
4 hours ago
Or dont use a script at all but a function defined in .bashrc
– Sergiy Kolodyazhnyy
4 hours ago