[Semibug] Setting environment variables [SOLVED]

Mark Moellering markmoellering at psyberation.com
Thu Aug 10 13:08:50 EDT 2023


I figured out I could put them in the csh.cshrc file, which put them in 
the root environment, which is all I needed, as root will call 
dehydrated via a cronjob.

I just had to put them in csh format instead of sh format.

Thanks for everyone's help.


-- Mark

On 8/10/23 12:11, Joe Price wrote:
> Just dealt with this situation this week..
>
> Have a look at https://stackoverflow.com/a/45971167
>
> This is essentially what I did in bash: set -a && source env_vars.sh 
> && set +a
>
>
> On 8/9/2023 7:37 PM, BCLUG wrote:
>> Mark Moellering wrote on 2023-08-09 13:24:
>>
>>> I am not sure what you mean by "test your script in a subshell" ...
>>
>> Usually a sub-shell is running something inside brackets, i.e.
>>
>> in the following example, the code inside brackets is slightly 
>> isolated from the `pwd` that runs afterwards:
>>
>>> $ (cd subshell-test/ ; pwd); pwd
>>> /tmp/semibug/subshell-test
>>> /tmp/semibug
>>
>>
>>> I am more of a programmer than an admin.
>>>
>>> Here is my script:
>>>
>>> -----------------------------------------------------
>>>
>>> #!/bin/sh
>>>
>>> GODADDY_KEY="xxxxxx"
>>> export GODADDY_KEY
>>>
>>> GODADDY_SECRET="yyyyyy"
>>> export GODADDY_SECRET
>>>
>>> -----------------------------------------------------
>>>
>>>
>>> The script runs and exits cleanly but if I run "env" afterwards, the 
>>> environment variables are not set.  I have no idea what I am doing 
>>> wrong.
>>
>> Code looks good, but it may be in how you're invoking it.
>>
>> If you `source` the script (one can use a `.` instead of the word 
>> `source` to run a script), then I believe the ENV vars ought to 
>> persist when the script finishes.
>>
>> If you set the shell to executable, or invoke it via `sh 
>> my_script.sh`, then that would (probably) count as a sub-shell and 
>> the ENV vars won't persist.
>>
>>
>> Hope that helps,
>>
>> rb
>>
>> _______________________________________________
>> Semibug mailing list
>> Semibug at lists.nycbug.org
>> https://lists.nycbug.org:8443/mailman/listinfo/semibug
>
> _______________________________________________
> Semibug mailing list
> Semibug at lists.nycbug.org
> https://lists.nycbug.org:8443/mailman/listinfo/semibug



More information about the Semibug mailing list