Goal: Create a Posix compatible sh script that uses an environment variable created by a sourced script.
/dir/var.sh contains only the following to create an environment variable.
export IPTABLES="/usr/sbin/iptables"
/dir/startup.sh contains the following.
#!/bin/sh
. /dir/var.sh
$IPTABLES options
command1 #Does not use an environmental variable
After startup.sh
completes, the variable is either not created or does not survive. Why ?
Note: the OS firmware is read-only. It does not allow editing the /etc/profile file to set environment variables to be available to all shells. Any script to export variables will execute too late.
/
directory (i.e. runcd /
first). – Wildcard Sep 19 '17 at 22:50. ./dir/var.sh
and see if you can spot what's wrong. – Wildcard Sep 19 '17 at 23:10. ./dir/var.sh
with. /dir/var.sh
and your script will work. This has nothing to do with environment variables, only to do with paths. – Wildcard Sep 19 '17 at 23:22