You are not logged in.

#1 2009-07-19 23:59:45

jeremyrainman
Member
Registered: 2007-06-15
Posts: 34

unable to set environment variable with ENV... [FIXED]

This:

$ sudo env MYTHCONFDIR=/home/mythtv

yields:

TERM=xterm
LS_COLORS=rs=0:...yadda yadda yadda....:*.spx=00;36:*.xspf=00;36:
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/kde/bin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:/opt/qt/bin
LC_COLLATE=C
LANG=en_US.utf8
PS1=\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[m\] \[\e[1;32m\]\$ \[\e[m\]\[\e[0;30m\]
PS2=> 
HOME=/home/jxxxxx
DISPLAY=:0.0
XAUTHORITY=/home/xxxxx/.Xauthority
COLORTERM=gnome-terminal
SHELL=/bin/bash
LOGNAME=root
USER=root
USERNAME=root
SUDO_COMMAND=/usr/bin/env MYTHCONFDIR=/home/mythtv
SUDO_USER=xxxxx
SUDO_UID=1000
SUDO_GID=1000
MYTHCONFDIR=/home/mythtv

but a subsequent '$ env' yields:

TERM=xterm
LS_COLORS=rs=0:...yadda yadda yadda....:*.spx=00;36:*.xspf=00;36:
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/kde/bin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:/opt/qt/bin
LC_COLLATE=C
LANG=en_US.utf8
PS1=\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[m\] \[\e[1;32m\]\$ \[\e[m\]\[\e[0;30m\]
PS2=> 
HOME=/home/jxxxxx
DISPLAY=:0.0
XAUTHORITY=/home/xxxxx/.Xauthority
COLORTERM=gnome-terminal
SHELL=/bin/bash
LOGNAME=root
USER=root
USERNAME=root
SUDO_COMMAND=/usr/bin/env MYTHCONFDIR=/home/mythtv
SUDO_USER=xxxxx
SUDO_UID=1000
SUDO_GID=1000

Notice, the environment variable I just set is now gone. Why would this be?

edit:
I have also tried adding the following to /etc/rc.conf

MYTHCONFDIR="/home/mythtv"

I have ALSO tried adding this:

env MYTHCONFDIR=/home/mythtv

to /etc/rc.local

However, for some reason this environmental variable just *WILL NOT STICK*.... This makes no sense to me. This is a clean install of Arch64

Last edited by jeremyrainman (2009-07-20 20:32:34)

Offline

#2 2009-07-20 01:37:59

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: unable to set environment variable with ENV... [FIXED]

env modifies the environment for a single command; it can't affect the environment of the calling shell.  You want 'export' which is a shell builtin and not a separate program.

Also, rc.conf and rc.local only affect certain scripts run at startup; they're not sourced by every shell.  If you want to initialize that variable for every shell, you want to put it in ~/.bashrc.

Offline

#3 2009-07-20 02:17:13

jeremyrainman
Member
Registered: 2007-06-15
Posts: 34

Re: unable to set environment variable with ENV... [FIXED]

Trent wrote:

Also, rc.conf and rc.local only affect certain scripts run at startup; they're not sourced by every shell.  If you want to initialize that variable for every shell, you want to put it in ~/.bashrc.

I don't need it for every "shell" as far as I know, I just need that variable to exist for when mythbackend is running and looking for it. mythbackend is started in rc.conf (listed as a daemon)

Last edited by jeremyrainman (2009-07-20 02:18:13)

Offline

#4 2009-07-20 04:45:44

sistematico
Member
From: Campo Grande / MS / Brasil
Registered: 2008-07-26
Posts: 97
Website

Re: unable to set environment variable with ENV... [FIXED]

rc.local makes more sense for me.

MYTHCONFDIR=/home/mythtv
export MYTHCONFDIR

I dont know, but env is for zsh, tcsh or similar shells.
Bash is more simple: ENV_VAR=value or export ENV_VAR=value for stick until reboot.

* Sorry for bad english.


Lucas Saliés Brum
blog | medium | vk | twitter | github | .share
Forgive the spelling and grammar, English is not my native language.

Offline

#5 2009-07-20 12:00:01

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: unable to set environment variable with ENV... [FIXED]

jeremyrainman wrote:

I don't need it for every "shell" as far as I know, I just need that variable to exist for when mythbackend is running and looking for it. mythbackend is started in rc.conf (listed as a daemon)

Then you want to start mythbackend with the variable set, e.g.

env MYTHCONFDIR=/home/mythtv /path/to/mythbackend start

(I don't know what the correct syntax is for mythbackend, correct as necessary).  You should also be able to set it in rc.conf (I think).

Once again, env is a program in /usr/bin; it can't affect the environment of whatever calls it.  It's only good for changing the environment of a program you tell it to call (which you didn't do in your first attempt, which explains why it only printed the environment and didn't do anything else).  systematico's post seems to indicate that env is a shell builtin in zsh and tcsh, which is entirely possible (it's been ages since I've used either).  rc.conf is used by the Bourne shell, so you need to use export if you wish to change the environment for subsequent calls of a program.

rc.local is sourced after all the daemons are started, so you need to put it in rc.conf (I think).  If that doesn't work, you can take it out of the DAEMONS array and start it in rc.local with the variable explicitly set.

Offline

#6 2009-07-20 20:32:19

jeremyrainman
Member
Registered: 2007-06-15
Posts: 34

Re: unable to set environment variable with ENV... [FIXED]

I fixed it by throwing an export command in rc.local, and using "su - mythtv /path/to/mythbackend"

right after. I still don't understand why:

MYTHCONFDIR=/home/mythtv

doesn't seem to work in my rc.conf.

Offline

#7 2009-07-22 02:29:31

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,029

Re: unable to set environment variable with ENV... [FIXED]

im having the same problem, i cant find a solution to it..
when run through the DAEMONS array in rc.conf, it fails to run, same error...

running with

 sudo /etc/rc.d/mythbackend start

starts correctly.. none of the solutions ive found on the web seem to fix it, and i dont want to touch the rc.d script for obvious reasons

Offline

Board footer

Powered by FluxBB