How export VAR to another script [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












How i can export this vars to another script. The other scrit need run to run some commands . I want that because the script is too big and i want to split it and put the var in another script




# Ficheiros onde serão guardados as palavras passes e os nomes do utilizadores
password_list="$HOME/passwords.txt"
user_list="$HOME/users.txt"
newpassword_list="$HOME/newuserpassword.txt"
# MAIL
DESTINATARIO="mail"
ENVIADOPOR="mail"
ASSUNTO="Palavra passe, utilizadores, hostname"
# SSHPASS
run1="sshpass -p $oldpass ssh host@ip"
run2="sshpass -p $newpassword ssh host@ip"
run3="sshpass -p $oldpass ssh host@ip"
run4="sshpass -p $newpassword ssh host@ip"
run5="sshpass -p $oldpass ssh redmine@ip"
run6="sshpass -p $newpassword ssh redmine@ip"







share|improve this question











closed as unclear what you're asking by ilkkachu, Jeff Schaller, steve, Anthony Geoghegan, Archemar May 9 at 15:55


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2




    uhh, have you looked into export at all?
    – DopeGhoti
    May 8 at 15:29










  • You'll want to use set -a to auto-export variables, and the source command... Actually, you don't need to export them, the script with the code just needs to source the script with the variables.
    – glenn jackman
    May 8 at 15:35







  • 1




    What variables do you want to export? What's the problem with doing it? What command do you want to export them to? The snippet you posted doesn't seem to run any external commands, it just sets some variables. Could you rewrite the comments in English, as that would make them easier to understand for most of use. Or just remove them, if they're not relevant to the question.
    – ilkkachu
    May 8 at 15:46














up vote
0
down vote

favorite












How i can export this vars to another script. The other scrit need run to run some commands . I want that because the script is too big and i want to split it and put the var in another script




# Ficheiros onde serão guardados as palavras passes e os nomes do utilizadores
password_list="$HOME/passwords.txt"
user_list="$HOME/users.txt"
newpassword_list="$HOME/newuserpassword.txt"
# MAIL
DESTINATARIO="mail"
ENVIADOPOR="mail"
ASSUNTO="Palavra passe, utilizadores, hostname"
# SSHPASS
run1="sshpass -p $oldpass ssh host@ip"
run2="sshpass -p $newpassword ssh host@ip"
run3="sshpass -p $oldpass ssh host@ip"
run4="sshpass -p $newpassword ssh host@ip"
run5="sshpass -p $oldpass ssh redmine@ip"
run6="sshpass -p $newpassword ssh redmine@ip"







share|improve this question











closed as unclear what you're asking by ilkkachu, Jeff Schaller, steve, Anthony Geoghegan, Archemar May 9 at 15:55


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2




    uhh, have you looked into export at all?
    – DopeGhoti
    May 8 at 15:29










  • You'll want to use set -a to auto-export variables, and the source command... Actually, you don't need to export them, the script with the code just needs to source the script with the variables.
    – glenn jackman
    May 8 at 15:35







  • 1




    What variables do you want to export? What's the problem with doing it? What command do you want to export them to? The snippet you posted doesn't seem to run any external commands, it just sets some variables. Could you rewrite the comments in English, as that would make them easier to understand for most of use. Or just remove them, if they're not relevant to the question.
    – ilkkachu
    May 8 at 15:46












up vote
0
down vote

favorite









up vote
0
down vote

favorite











How i can export this vars to another script. The other scrit need run to run some commands . I want that because the script is too big and i want to split it and put the var in another script




# Ficheiros onde serão guardados as palavras passes e os nomes do utilizadores
password_list="$HOME/passwords.txt"
user_list="$HOME/users.txt"
newpassword_list="$HOME/newuserpassword.txt"
# MAIL
DESTINATARIO="mail"
ENVIADOPOR="mail"
ASSUNTO="Palavra passe, utilizadores, hostname"
# SSHPASS
run1="sshpass -p $oldpass ssh host@ip"
run2="sshpass -p $newpassword ssh host@ip"
run3="sshpass -p $oldpass ssh host@ip"
run4="sshpass -p $newpassword ssh host@ip"
run5="sshpass -p $oldpass ssh redmine@ip"
run6="sshpass -p $newpassword ssh redmine@ip"







share|improve this question











How i can export this vars to another script. The other scrit need run to run some commands . I want that because the script is too big and i want to split it and put the var in another script




# Ficheiros onde serão guardados as palavras passes e os nomes do utilizadores
password_list="$HOME/passwords.txt"
user_list="$HOME/users.txt"
newpassword_list="$HOME/newuserpassword.txt"
# MAIL
DESTINATARIO="mail"
ENVIADOPOR="mail"
ASSUNTO="Palavra passe, utilizadores, hostname"
# SSHPASS
run1="sshpass -p $oldpass ssh host@ip"
run2="sshpass -p $newpassword ssh host@ip"
run3="sshpass -p $oldpass ssh host@ip"
run4="sshpass -p $newpassword ssh host@ip"
run5="sshpass -p $oldpass ssh redmine@ip"
run6="sshpass -p $newpassword ssh redmine@ip"









share|improve this question










share|improve this question




share|improve this question









asked May 8 at 14:18









helpme123

33




33




closed as unclear what you're asking by ilkkachu, Jeff Schaller, steve, Anthony Geoghegan, Archemar May 9 at 15:55


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by ilkkachu, Jeff Schaller, steve, Anthony Geoghegan, Archemar May 9 at 15:55


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    uhh, have you looked into export at all?
    – DopeGhoti
    May 8 at 15:29










  • You'll want to use set -a to auto-export variables, and the source command... Actually, you don't need to export them, the script with the code just needs to source the script with the variables.
    – glenn jackman
    May 8 at 15:35







  • 1




    What variables do you want to export? What's the problem with doing it? What command do you want to export them to? The snippet you posted doesn't seem to run any external commands, it just sets some variables. Could you rewrite the comments in English, as that would make them easier to understand for most of use. Or just remove them, if they're not relevant to the question.
    – ilkkachu
    May 8 at 15:46












  • 2




    uhh, have you looked into export at all?
    – DopeGhoti
    May 8 at 15:29










  • You'll want to use set -a to auto-export variables, and the source command... Actually, you don't need to export them, the script with the code just needs to source the script with the variables.
    – glenn jackman
    May 8 at 15:35







  • 1




    What variables do you want to export? What's the problem with doing it? What command do you want to export them to? The snippet you posted doesn't seem to run any external commands, it just sets some variables. Could you rewrite the comments in English, as that would make them easier to understand for most of use. Or just remove them, if they're not relevant to the question.
    – ilkkachu
    May 8 at 15:46







2




2




uhh, have you looked into export at all?
– DopeGhoti
May 8 at 15:29




uhh, have you looked into export at all?
– DopeGhoti
May 8 at 15:29












You'll want to use set -a to auto-export variables, and the source command... Actually, you don't need to export them, the script with the code just needs to source the script with the variables.
– glenn jackman
May 8 at 15:35





You'll want to use set -a to auto-export variables, and the source command... Actually, you don't need to export them, the script with the code just needs to source the script with the variables.
– glenn jackman
May 8 at 15:35





1




1




What variables do you want to export? What's the problem with doing it? What command do you want to export them to? The snippet you posted doesn't seem to run any external commands, it just sets some variables. Could you rewrite the comments in English, as that would make them easier to understand for most of use. Or just remove them, if they're not relevant to the question.
– ilkkachu
May 8 at 15:46




What variables do you want to export? What's the problem with doing it? What command do you want to export them to? The snippet you posted doesn't seem to run any external commands, it just sets some variables. Could you rewrite the comments in English, as that would make them easier to understand for most of use. Or just remove them, if they're not relevant to the question.
– ilkkachu
May 8 at 15:46










1 Answer
1






active

oldest

votes

















up vote
1
down vote













To basically answer your question, the "export" keyword before variable assignment will make if available to all sub-shells you'll run, example:



export DESTINATARIO="mail"


Howerver, if the reason is that your script is "too big", you may also consider organizing your shell scripts into libraries, with a top script calling functions in included files. Example:



#!/bin/bash
# load functions defined in mylib1.sh and mylib2.sh
source mylib1.sh
source mylib2.sh
# set my var
VAR1=123abc
# call functions from mylib1.sh and mylib2.sh
lib1func1 $VAR1
lib2func2 $VAR1


Having for example in mylib1.sh the function definition of lib1func1:



lib1func1() 
local firstvar=$1 # reading
echo $firstvar



Of course, the top shell can also export variables (globals) that the libraries will know, but I would not encvourage this way, since it is less modular.






share|improve this answer





















  • Just to be complete, it should be mentioned that if you run a script that has an export in it, when the script terminates, you will not have the variable set. To have it kept after the script terminates, you need instead to source the script.
    – ChatterOne
    May 9 at 11:46

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













To basically answer your question, the "export" keyword before variable assignment will make if available to all sub-shells you'll run, example:



export DESTINATARIO="mail"


Howerver, if the reason is that your script is "too big", you may also consider organizing your shell scripts into libraries, with a top script calling functions in included files. Example:



#!/bin/bash
# load functions defined in mylib1.sh and mylib2.sh
source mylib1.sh
source mylib2.sh
# set my var
VAR1=123abc
# call functions from mylib1.sh and mylib2.sh
lib1func1 $VAR1
lib2func2 $VAR1


Having for example in mylib1.sh the function definition of lib1func1:



lib1func1() 
local firstvar=$1 # reading
echo $firstvar



Of course, the top shell can also export variables (globals) that the libraries will know, but I would not encvourage this way, since it is less modular.






share|improve this answer





















  • Just to be complete, it should be mentioned that if you run a script that has an export in it, when the script terminates, you will not have the variable set. To have it kept after the script terminates, you need instead to source the script.
    – ChatterOne
    May 9 at 11:46














up vote
1
down vote













To basically answer your question, the "export" keyword before variable assignment will make if available to all sub-shells you'll run, example:



export DESTINATARIO="mail"


Howerver, if the reason is that your script is "too big", you may also consider organizing your shell scripts into libraries, with a top script calling functions in included files. Example:



#!/bin/bash
# load functions defined in mylib1.sh and mylib2.sh
source mylib1.sh
source mylib2.sh
# set my var
VAR1=123abc
# call functions from mylib1.sh and mylib2.sh
lib1func1 $VAR1
lib2func2 $VAR1


Having for example in mylib1.sh the function definition of lib1func1:



lib1func1() 
local firstvar=$1 # reading
echo $firstvar



Of course, the top shell can also export variables (globals) that the libraries will know, but I would not encvourage this way, since it is less modular.






share|improve this answer





















  • Just to be complete, it should be mentioned that if you run a script that has an export in it, when the script terminates, you will not have the variable set. To have it kept after the script terminates, you need instead to source the script.
    – ChatterOne
    May 9 at 11:46












up vote
1
down vote










up vote
1
down vote









To basically answer your question, the "export" keyword before variable assignment will make if available to all sub-shells you'll run, example:



export DESTINATARIO="mail"


Howerver, if the reason is that your script is "too big", you may also consider organizing your shell scripts into libraries, with a top script calling functions in included files. Example:



#!/bin/bash
# load functions defined in mylib1.sh and mylib2.sh
source mylib1.sh
source mylib2.sh
# set my var
VAR1=123abc
# call functions from mylib1.sh and mylib2.sh
lib1func1 $VAR1
lib2func2 $VAR1


Having for example in mylib1.sh the function definition of lib1func1:



lib1func1() 
local firstvar=$1 # reading
echo $firstvar



Of course, the top shell can also export variables (globals) that the libraries will know, but I would not encvourage this way, since it is less modular.






share|improve this answer













To basically answer your question, the "export" keyword before variable assignment will make if available to all sub-shells you'll run, example:



export DESTINATARIO="mail"


Howerver, if the reason is that your script is "too big", you may also consider organizing your shell scripts into libraries, with a top script calling functions in included files. Example:



#!/bin/bash
# load functions defined in mylib1.sh and mylib2.sh
source mylib1.sh
source mylib2.sh
# set my var
VAR1=123abc
# call functions from mylib1.sh and mylib2.sh
lib1func1 $VAR1
lib2func2 $VAR1


Having for example in mylib1.sh the function definition of lib1func1:



lib1func1() 
local firstvar=$1 # reading
echo $firstvar



Of course, the top shell can also export variables (globals) that the libraries will know, but I would not encvourage this way, since it is less modular.







share|improve this answer













share|improve this answer



share|improve this answer











answered May 8 at 15:41









tonioc

1,11457




1,11457











  • Just to be complete, it should be mentioned that if you run a script that has an export in it, when the script terminates, you will not have the variable set. To have it kept after the script terminates, you need instead to source the script.
    – ChatterOne
    May 9 at 11:46
















  • Just to be complete, it should be mentioned that if you run a script that has an export in it, when the script terminates, you will not have the variable set. To have it kept after the script terminates, you need instead to source the script.
    – ChatterOne
    May 9 at 11:46















Just to be complete, it should be mentioned that if you run a script that has an export in it, when the script terminates, you will not have the variable set. To have it kept after the script terminates, you need instead to source the script.
– ChatterOne
May 9 at 11:46




Just to be complete, it should be mentioned that if you run a script that has an export in it, when the script terminates, you will not have the variable set. To have it kept after the script terminates, you need instead to source the script.
– ChatterOne
May 9 at 11:46


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay