Defining shell variables

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
We have problem defining variables between two shell scripts, basically what we want to do is run ./get_variables.sh, and fill in the details for "Enter the domain: " and "Enter the vestacp password:" then get the details as variables in vestacp.sh
get_variables.sh content
#!/bin/sh
echo "Enter the domain: "
read $domain
echo "Enter the vestacp password:"
read $rvp
/root/vestacp.sh $domain $rvp
and
vestacp.sh content
sed -i s/VAR1/$domain/g config.php
sed -i s/VAR2/$rvp/g config.php
config.php file content
VAR1
VAR2
VAR1 and VAR2 should be replaced by the data that we enter when running ./get_variables.sh using sed on vestacp.sh
The problem that we are getting just an empty config.php after running ./get_variables.sh
linux sed
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
We have problem defining variables between two shell scripts, basically what we want to do is run ./get_variables.sh, and fill in the details for "Enter the domain: " and "Enter the vestacp password:" then get the details as variables in vestacp.sh
get_variables.sh content
#!/bin/sh
echo "Enter the domain: "
read $domain
echo "Enter the vestacp password:"
read $rvp
/root/vestacp.sh $domain $rvp
and
vestacp.sh content
sed -i s/VAR1/$domain/g config.php
sed -i s/VAR2/$rvp/g config.php
config.php file content
VAR1
VAR2
VAR1 and VAR2 should be replaced by the data that we enter when running ./get_variables.sh using sed on vestacp.sh
The problem that we are getting just an empty config.php after running ./get_variables.sh
linux sed
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Yes, and? What did you try, what did you expect to happen, what did actually happen? (Hint: you probably want to source./get_variables.shwith. ./get_variables.sh, not run it.)
– AlexP
Nov 21 at 23:29
2
why are you doingread $domainand notread domain?
– thrig
Nov 21 at 23:41
1
shellcheck.net will help with the typical shell errors
– glenn jackman
Nov 21 at 23:49
Relating: unix.stackexchange.com/questions/129059/…
– Jeff Schaller
Nov 22 at 0:31
Also possibly related: Why does my shell script choke on whitespace or other special characters?
– Kusalananda
Nov 22 at 7:34
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
We have problem defining variables between two shell scripts, basically what we want to do is run ./get_variables.sh, and fill in the details for "Enter the domain: " and "Enter the vestacp password:" then get the details as variables in vestacp.sh
get_variables.sh content
#!/bin/sh
echo "Enter the domain: "
read $domain
echo "Enter the vestacp password:"
read $rvp
/root/vestacp.sh $domain $rvp
and
vestacp.sh content
sed -i s/VAR1/$domain/g config.php
sed -i s/VAR2/$rvp/g config.php
config.php file content
VAR1
VAR2
VAR1 and VAR2 should be replaced by the data that we enter when running ./get_variables.sh using sed on vestacp.sh
The problem that we are getting just an empty config.php after running ./get_variables.sh
linux sed
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
We have problem defining variables between two shell scripts, basically what we want to do is run ./get_variables.sh, and fill in the details for "Enter the domain: " and "Enter the vestacp password:" then get the details as variables in vestacp.sh
get_variables.sh content
#!/bin/sh
echo "Enter the domain: "
read $domain
echo "Enter the vestacp password:"
read $rvp
/root/vestacp.sh $domain $rvp
and
vestacp.sh content
sed -i s/VAR1/$domain/g config.php
sed -i s/VAR2/$rvp/g config.php
config.php file content
VAR1
VAR2
VAR1 and VAR2 should be replaced by the data that we enter when running ./get_variables.sh using sed on vestacp.sh
The problem that we are getting just an empty config.php after running ./get_variables.sh
linux sed
linux sed
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 22 at 13:44
ctrl-alt-delor
10.2k41955
10.2k41955
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 21 at 23:19
Ali EL KANDOUSSI
54
54
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Yes, and? What did you try, what did you expect to happen, what did actually happen? (Hint: you probably want to source./get_variables.shwith. ./get_variables.sh, not run it.)
– AlexP
Nov 21 at 23:29
2
why are you doingread $domainand notread domain?
– thrig
Nov 21 at 23:41
1
shellcheck.net will help with the typical shell errors
– glenn jackman
Nov 21 at 23:49
Relating: unix.stackexchange.com/questions/129059/…
– Jeff Schaller
Nov 22 at 0:31
Also possibly related: Why does my shell script choke on whitespace or other special characters?
– Kusalananda
Nov 22 at 7:34
add a comment |
Yes, and? What did you try, what did you expect to happen, what did actually happen? (Hint: you probably want to source./get_variables.shwith. ./get_variables.sh, not run it.)
– AlexP
Nov 21 at 23:29
2
why are you doingread $domainand notread domain?
– thrig
Nov 21 at 23:41
1
shellcheck.net will help with the typical shell errors
– glenn jackman
Nov 21 at 23:49
Relating: unix.stackexchange.com/questions/129059/…
– Jeff Schaller
Nov 22 at 0:31
Also possibly related: Why does my shell script choke on whitespace or other special characters?
– Kusalananda
Nov 22 at 7:34
Yes, and? What did you try, what did you expect to happen, what did actually happen? (Hint: you probably want to source
./get_variables.sh with . ./get_variables.sh, not run it.)– AlexP
Nov 21 at 23:29
Yes, and? What did you try, what did you expect to happen, what did actually happen? (Hint: you probably want to source
./get_variables.sh with . ./get_variables.sh, not run it.)– AlexP
Nov 21 at 23:29
2
2
why are you doing
read $domain and not read domain ?– thrig
Nov 21 at 23:41
why are you doing
read $domain and not read domain ?– thrig
Nov 21 at 23:41
1
1
shellcheck.net will help with the typical shell errors
– glenn jackman
Nov 21 at 23:49
shellcheck.net will help with the typical shell errors
– glenn jackman
Nov 21 at 23:49
Relating: unix.stackexchange.com/questions/129059/…
– Jeff Schaller
Nov 22 at 0:31
Relating: unix.stackexchange.com/questions/129059/…
– Jeff Schaller
Nov 22 at 0:31
Also possibly related: Why does my shell script choke on whitespace or other special characters?
– Kusalananda
Nov 22 at 7:34
Also possibly related: Why does my shell script choke on whitespace or other special characters?
– Kusalananda
Nov 22 at 7:34
add a comment |
1 Answer
1
active
oldest
votes
up vote
-1
down vote
accepted
I see two errors:
read variableshould not have a$- variables are not passed by name. The 2nd script is trying to read a variable by the name it was called in the 1st script. It can not know what it was called in first script.
Also break your problems down. There is no way that anyone can write a big program, and then run it, and it work. It this case test each script separately. Get then to work, on their own, then get them to work together.
Also use shellcheck to test you scripts. It will find some of the errors. You will still have to test it. sudo apt-get install shellcheck to install on Debian.
It's working thanks, The problem was $ before variables, removed them all, the script is working now
– Ali EL KANDOUSSI
Nov 22 at 13:55
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
I see two errors:
read variableshould not have a$- variables are not passed by name. The 2nd script is trying to read a variable by the name it was called in the 1st script. It can not know what it was called in first script.
Also break your problems down. There is no way that anyone can write a big program, and then run it, and it work. It this case test each script separately. Get then to work, on their own, then get them to work together.
Also use shellcheck to test you scripts. It will find some of the errors. You will still have to test it. sudo apt-get install shellcheck to install on Debian.
It's working thanks, The problem was $ before variables, removed them all, the script is working now
– Ali EL KANDOUSSI
Nov 22 at 13:55
add a comment |
up vote
-1
down vote
accepted
I see two errors:
read variableshould not have a$- variables are not passed by name. The 2nd script is trying to read a variable by the name it was called in the 1st script. It can not know what it was called in first script.
Also break your problems down. There is no way that anyone can write a big program, and then run it, and it work. It this case test each script separately. Get then to work, on their own, then get them to work together.
Also use shellcheck to test you scripts. It will find some of the errors. You will still have to test it. sudo apt-get install shellcheck to install on Debian.
It's working thanks, The problem was $ before variables, removed them all, the script is working now
– Ali EL KANDOUSSI
Nov 22 at 13:55
add a comment |
up vote
-1
down vote
accepted
up vote
-1
down vote
accepted
I see two errors:
read variableshould not have a$- variables are not passed by name. The 2nd script is trying to read a variable by the name it was called in the 1st script. It can not know what it was called in first script.
Also break your problems down. There is no way that anyone can write a big program, and then run it, and it work. It this case test each script separately. Get then to work, on their own, then get them to work together.
Also use shellcheck to test you scripts. It will find some of the errors. You will still have to test it. sudo apt-get install shellcheck to install on Debian.
I see two errors:
read variableshould not have a$- variables are not passed by name. The 2nd script is trying to read a variable by the name it was called in the 1st script. It can not know what it was called in first script.
Also break your problems down. There is no way that anyone can write a big program, and then run it, and it work. It this case test each script separately. Get then to work, on their own, then get them to work together.
Also use shellcheck to test you scripts. It will find some of the errors. You will still have to test it. sudo apt-get install shellcheck to install on Debian.
edited Nov 22 at 13:52
answered Nov 22 at 13:47
ctrl-alt-delor
10.2k41955
10.2k41955
It's working thanks, The problem was $ before variables, removed them all, the script is working now
– Ali EL KANDOUSSI
Nov 22 at 13:55
add a comment |
It's working thanks, The problem was $ before variables, removed them all, the script is working now
– Ali EL KANDOUSSI
Nov 22 at 13:55
It's working thanks, The problem was $ before variables, removed them all, the script is working now
– Ali EL KANDOUSSI
Nov 22 at 13:55
It's working thanks, The problem was $ before variables, removed them all, the script is working now
– Ali EL KANDOUSSI
Nov 22 at 13:55
add a comment |
Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.
Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.
Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.
Ali EL KANDOUSSI 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%2funix.stackexchange.com%2fquestions%2f483324%2fdefining-shell-variables%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
Yes, and? What did you try, what did you expect to happen, what did actually happen? (Hint: you probably want to source
./get_variables.shwith. ./get_variables.sh, not run it.)– AlexP
Nov 21 at 23:29
2
why are you doing
read $domainand notread domain?– thrig
Nov 21 at 23:41
1
shellcheck.net will help with the typical shell errors
– glenn jackman
Nov 21 at 23:49
Relating: unix.stackexchange.com/questions/129059/…
– Jeff Schaller
Nov 22 at 0:31
Also possibly related: Why does my shell script choke on whitespace or other special characters?
– Kusalananda
Nov 22 at 7:34