0

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

1 Answers1

-1

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.