I want to send the path to a bash script which sources some environmental variables as an argument to another bash script to run it and use the environmental variables. It works well with no arguments if I hard coded the path to the bash script to run it works and I can retrieve the environmental variables in the main script. the problem happens when I send the path as an argument it does not want to run it. for example if the path is /path/script.bash and I send the path as an argument I get the error that /path/env_set: No such a file or directory I run the script by this line
. $1 (this doesn't work)
. /path/script.bash (this works)
if I use
bash -c $1
the bash file runs but it does not set the environmental variables to use it in the main script
I don't know why env_set replaces the script name when I use arguments. Is there any approach to achieve this or any work around to achieve my goal?
. $1in bash on my computer and it runs as expected. I advise you to put double quotes around"$1"for the case the path to your script contains spaces.env_setand show a little bit more of your code. Try to make a minimal reproducible example, as usual on SO.set -xat the beginning of the script to get an execution trace may help clarify what's going on.