What's new

Where to create an environmental variable ?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Denna

Senior Member
If you want to create an environmental variable with the "export" command, what script should it run from ?
 
profile.add.
 
Source the profile file at the start of your postconf script. profile.add only adds env vars when a user logs in over ssh, it can't be retroactively applied to already running processes such as rc.
 
Does the script have to be profile.add or can it be any executable script ?

For example, /jffs/scripts/env-vars.sh contains ...
Code:
export IPSET="/usr/sbin/ipset"
/jffs/scripts dnsmasq.postconf contains ...
Code:
#!/bin/sh

. /jffs/scripts/env_vars.sh
$IPSET options
When you source a file in a proper script, it does not matter where or what form the file is in as long as what is written in it is understood and valid.
No shebang, no executable rights needed for that file.
Test it!
 
Scenario #1:
a) When sourcing ". /jffs/configs/profile.add" in /jffs/scripts/dnsmasq.postconf, the environment variable is set.
Scenario #2:
a) The profile.add file was copied to /jffs/scripts and renamed to env_vars.sh.
b) The commands in /jffs/configs/profile.add were commented out.
c) When sourcing ". /jffs/scripts/env_vars.sh" in /jffs/scripts/dnsmasq.postconf, the environment variable is not set.​
 
Scenario #1:
a) When sourcing ". /jffs/configs/profile.add" in /jffs/scripts/dnsmasq.postconf, the environment variable is set.
Scenario #2:
a) The profile.add file was copied to /jffs/scripts and renamed to env_vars.sh.
b) The commands in /jffs/configs/profile.add were commented out.
c) When sourcing ". /jffs/scripts/env_vars.sh" in /jffs/scripts/dnsmasq.postconf, the environment variable is not set.​
No reason not to.
Why don't you try and figure out why by yourself?
 
@RMerlin,

Is this correct ? At bootup ...
  • /etc/profile is processed before dnsmasq.postconf
  • The profile.add script runs after dnsmasq.postconf
  • Since /etc/profile is read-only, by sourcing profile.add in dnsmasq.postconf, the variables are made available to all shells that would normally only be present after a user logs into the OS.
  • For any sourced script in dnsmasq.postconf that creates variables, those variables will not be available to dnsmasq.postconf when the sourced script exits
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top