Set environment variables in bash file calling a Matlab script
up vote
0
down vote
favorite
I have the following bash file launching some Matlab m-files (main.m and f.m which are scripts) 4 times (4 tasks).
#$ -S /bin/bash
#$ -l h_vmem=4G
#$ -l tmem=4G
#$ -cwd
#$ -j y
#Run 4 tasks where each task has a different $SGE_TASK_ID ranging from 1 to 4
#$ -t 1-4
#$ -N example
date
hostname
#Output the Task ID
echo "Task ID is $SGE_TASK_ID"
/share/apps/[...]/matlab -nodisplay -nodesktop -nojvm -nosplash -r "main; ID = $SGE_TASK_ID; f; exit"
The f.m script uses the Gurobi toolbox and I have been told that in order for the file to execute properly I have to set the environment variable
GRB=/apps/[...].lic
where [...] contains the path.
I am a very beginner on how to write bash files and I apologise if my question is silly: where/how/what should I write on the batch file above to use the Gurobi toolbox?
I have googled on how to set environment variables but I got confused between setting, exporting, env. There are many similar questions on in this forum but, since they apply to apparently differently structured batch files, I couldn't understand whether their answers can be tailored also to my case.
bash matlab environment-variables
add a comment |
up vote
0
down vote
favorite
I have the following bash file launching some Matlab m-files (main.m and f.m which are scripts) 4 times (4 tasks).
#$ -S /bin/bash
#$ -l h_vmem=4G
#$ -l tmem=4G
#$ -cwd
#$ -j y
#Run 4 tasks where each task has a different $SGE_TASK_ID ranging from 1 to 4
#$ -t 1-4
#$ -N example
date
hostname
#Output the Task ID
echo "Task ID is $SGE_TASK_ID"
/share/apps/[...]/matlab -nodisplay -nodesktop -nojvm -nosplash -r "main; ID = $SGE_TASK_ID; f; exit"
The f.m script uses the Gurobi toolbox and I have been told that in order for the file to execute properly I have to set the environment variable
GRB=/apps/[...].lic
where [...] contains the path.
I am a very beginner on how to write bash files and I apologise if my question is silly: where/how/what should I write on the batch file above to use the Gurobi toolbox?
I have googled on how to set environment variables but I got confused between setting, exporting, env. There are many similar questions on in this forum but, since they apply to apparently differently structured batch files, I couldn't understand whether their answers can be tailored also to my case.
bash matlab environment-variables
1
Replaced the obviously wrong tag [batch-file] with [bash]
– LotPings
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following bash file launching some Matlab m-files (main.m and f.m which are scripts) 4 times (4 tasks).
#$ -S /bin/bash
#$ -l h_vmem=4G
#$ -l tmem=4G
#$ -cwd
#$ -j y
#Run 4 tasks where each task has a different $SGE_TASK_ID ranging from 1 to 4
#$ -t 1-4
#$ -N example
date
hostname
#Output the Task ID
echo "Task ID is $SGE_TASK_ID"
/share/apps/[...]/matlab -nodisplay -nodesktop -nojvm -nosplash -r "main; ID = $SGE_TASK_ID; f; exit"
The f.m script uses the Gurobi toolbox and I have been told that in order for the file to execute properly I have to set the environment variable
GRB=/apps/[...].lic
where [...] contains the path.
I am a very beginner on how to write bash files and I apologise if my question is silly: where/how/what should I write on the batch file above to use the Gurobi toolbox?
I have googled on how to set environment variables but I got confused between setting, exporting, env. There are many similar questions on in this forum but, since they apply to apparently differently structured batch files, I couldn't understand whether their answers can be tailored also to my case.
bash matlab environment-variables
I have the following bash file launching some Matlab m-files (main.m and f.m which are scripts) 4 times (4 tasks).
#$ -S /bin/bash
#$ -l h_vmem=4G
#$ -l tmem=4G
#$ -cwd
#$ -j y
#Run 4 tasks where each task has a different $SGE_TASK_ID ranging from 1 to 4
#$ -t 1-4
#$ -N example
date
hostname
#Output the Task ID
echo "Task ID is $SGE_TASK_ID"
/share/apps/[...]/matlab -nodisplay -nodesktop -nojvm -nosplash -r "main; ID = $SGE_TASK_ID; f; exit"
The f.m script uses the Gurobi toolbox and I have been told that in order for the file to execute properly I have to set the environment variable
GRB=/apps/[...].lic
where [...] contains the path.
I am a very beginner on how to write bash files and I apologise if my question is silly: where/how/what should I write on the batch file above to use the Gurobi toolbox?
I have googled on how to set environment variables but I got confused between setting, exporting, env. There are many similar questions on in this forum but, since they apply to apparently differently structured batch files, I couldn't understand whether their answers can be tailored also to my case.
bash matlab environment-variables
bash matlab environment-variables
edited yesterday
asked yesterday
user3285148
631525
631525
1
Replaced the obviously wrong tag [batch-file] with [bash]
– LotPings
yesterday
add a comment |
1
Replaced the obviously wrong tag [batch-file] with [bash]
– LotPings
yesterday
1
1
Replaced the obviously wrong tag [batch-file] with [bash]
– LotPings
yesterday
Replaced the obviously wrong tag [batch-file] with [bash]
– LotPings
yesterday
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
Within your bash file, just add the following line before launching the matlab m-files:
export GRB="/apps/[...].lic"
add a comment |
up vote
2
down vote
Environment variables are owned by a process, a running process can't change environment of another running process, when creating a new process exported variables of parent are set in child process by default, the environment variables changed in child process can't affect parent process.
GRB=/apps/[...].lic will set variable GRB to a value in bash process it can be seen using echo "$GRB" for example but this variable is not exported, means that when calling matlab, for matlab process environment variable GRB will not be set. Using export GRB before calling matlab will make the variable exported to matlab process.
There's also a syntax to set environment variable for a new process without affecting current bash process: GRB=/apps/[...].lic /share/apps/[...]/matlab ....
For further details man bash /export /^ENVIRONMENT
Also compare output of following commands, set (a builtin, a bash "function" no new process created), env (/usr/bin/env a command, a new process is created and only sees exported variables)
$ set
$ env
the first shows variables, whereas the second environnment which is a subset of first.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Within your bash file, just add the following line before launching the matlab m-files:
export GRB="/apps/[...].lic"
add a comment |
up vote
2
down vote
accepted
Within your bash file, just add the following line before launching the matlab m-files:
export GRB="/apps/[...].lic"
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Within your bash file, just add the following line before launching the matlab m-files:
export GRB="/apps/[...].lic"
Within your bash file, just add the following line before launching the matlab m-files:
export GRB="/apps/[...].lic"
answered yesterday
Muttley
2748
2748
add a comment |
add a comment |
up vote
2
down vote
Environment variables are owned by a process, a running process can't change environment of another running process, when creating a new process exported variables of parent are set in child process by default, the environment variables changed in child process can't affect parent process.
GRB=/apps/[...].lic will set variable GRB to a value in bash process it can be seen using echo "$GRB" for example but this variable is not exported, means that when calling matlab, for matlab process environment variable GRB will not be set. Using export GRB before calling matlab will make the variable exported to matlab process.
There's also a syntax to set environment variable for a new process without affecting current bash process: GRB=/apps/[...].lic /share/apps/[...]/matlab ....
For further details man bash /export /^ENVIRONMENT
Also compare output of following commands, set (a builtin, a bash "function" no new process created), env (/usr/bin/env a command, a new process is created and only sees exported variables)
$ set
$ env
the first shows variables, whereas the second environnment which is a subset of first.
add a comment |
up vote
2
down vote
Environment variables are owned by a process, a running process can't change environment of another running process, when creating a new process exported variables of parent are set in child process by default, the environment variables changed in child process can't affect parent process.
GRB=/apps/[...].lic will set variable GRB to a value in bash process it can be seen using echo "$GRB" for example but this variable is not exported, means that when calling matlab, for matlab process environment variable GRB will not be set. Using export GRB before calling matlab will make the variable exported to matlab process.
There's also a syntax to set environment variable for a new process without affecting current bash process: GRB=/apps/[...].lic /share/apps/[...]/matlab ....
For further details man bash /export /^ENVIRONMENT
Also compare output of following commands, set (a builtin, a bash "function" no new process created), env (/usr/bin/env a command, a new process is created and only sees exported variables)
$ set
$ env
the first shows variables, whereas the second environnment which is a subset of first.
add a comment |
up vote
2
down vote
up vote
2
down vote
Environment variables are owned by a process, a running process can't change environment of another running process, when creating a new process exported variables of parent are set in child process by default, the environment variables changed in child process can't affect parent process.
GRB=/apps/[...].lic will set variable GRB to a value in bash process it can be seen using echo "$GRB" for example but this variable is not exported, means that when calling matlab, for matlab process environment variable GRB will not be set. Using export GRB before calling matlab will make the variable exported to matlab process.
There's also a syntax to set environment variable for a new process without affecting current bash process: GRB=/apps/[...].lic /share/apps/[...]/matlab ....
For further details man bash /export /^ENVIRONMENT
Also compare output of following commands, set (a builtin, a bash "function" no new process created), env (/usr/bin/env a command, a new process is created and only sees exported variables)
$ set
$ env
the first shows variables, whereas the second environnment which is a subset of first.
Environment variables are owned by a process, a running process can't change environment of another running process, when creating a new process exported variables of parent are set in child process by default, the environment variables changed in child process can't affect parent process.
GRB=/apps/[...].lic will set variable GRB to a value in bash process it can be seen using echo "$GRB" for example but this variable is not exported, means that when calling matlab, for matlab process environment variable GRB will not be set. Using export GRB before calling matlab will make the variable exported to matlab process.
There's also a syntax to set environment variable for a new process without affecting current bash process: GRB=/apps/[...].lic /share/apps/[...]/matlab ....
For further details man bash /export /^ENVIRONMENT
Also compare output of following commands, set (a builtin, a bash "function" no new process created), env (/usr/bin/env a command, a new process is created and only sees exported variables)
$ set
$ env
the first shows variables, whereas the second environnment which is a subset of first.
edited yesterday
answered yesterday
Nahuel Fouilleul
13.7k1525
13.7k1525
add a comment |
add a comment |
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223693%2fset-environment-variables-in-bash-file-calling-a-matlab-script%23new-answer', 'question_page');
);
Post as a guest
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
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
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
1
Replaced the obviously wrong tag [batch-file] with [bash]
– LotPings
yesterday