Defining shell variables

The name of the pictureThe name of the pictureThe name of the pictureClash 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










share|improve this question









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.sh with . ./get_variables.sh, not run it.)
    – AlexP
    Nov 21 at 23:29







  • 2




    why are you doing read $domain and not read 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














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










share|improve this question









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.sh with . ./get_variables.sh, not run it.)
    – AlexP
    Nov 21 at 23:29







  • 2




    why are you doing read $domain and not read 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












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










share|improve this question









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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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.sh with . ./get_variables.sh, not run it.)
    – AlexP
    Nov 21 at 23:29







  • 2




    why are you doing read $domain and not read 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







  • 2




    why are you doing read $domain and not read 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










1 Answer
1






active

oldest

votes

















up vote
-1
down vote



accepted










I see two errors:




  • read variable should 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.






share|improve this answer






















  • 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










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);



);






Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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

























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 variable should 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.






share|improve this answer






















  • 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














up vote
-1
down vote



accepted










I see two errors:




  • read variable should 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.






share|improve this answer






















  • 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












up vote
-1
down vote



accepted







up vote
-1
down vote



accepted






I see two errors:




  • read variable should 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.






share|improve this answer














I see two errors:




  • read variable should 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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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










Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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





















































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






Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)