Is their any way we can get env variables values in custom script ?
1 Answer
Have a look at \Magento\Framework\App\DeploymentConfig:
Inject a deployment config object of \Magento\Framework\App\DeploymentConfig in your code and then retrieve the value like this:
$deploymentConfig->get('db/connection/default/host');
For Example:
$deploymentConfig->get('your/custom/value');
Courtesy: Magento 2. Retrieve information from env.php programmatically