Solved How do I set an environment variable in the FreeBSD shell?

This is probably a simple question but I am a bit confused about how to even find the answer.

I am using FreeBSD 9.2-STABLE. I just need to set an environment variable called NNTPSERVER to the name of my ISP server. Suppose the server is called "news.someisp.com" I do not know what file to edit or exactly what form the entry should take.

I can see files in my home directory for shell configuration: .cshrc and .shrc.

I read that the shell the system uses is sh, but then I also read the shell is actually tcsh. I do not even know what the shell is that I am using. I have made no changes to the default setup. Can anyone tell me what the installed shell is and how to set the environment variable?
 
Just stumbled across the same problem:

To add a new global variable for your bash (sh) first you have to use man sh, there, in the 4th paragraph we read:

..A login shell first reads commands from the
files /etc/profile and then .profile in a user's home directory, if they
exist...

So, we need to copy a .profile in our home dir. (in case it doesn't exist) or edit the existent one to include our folder address. So I had to do:
edited: cp /usr/share/skel/dot.profile /usr/home/<username>/.profile (thanks kpa SirDice ). I used the /usr/share/skel/dot.profile as a template.

Note: The skeleton folder ( /usr/share/skel) is used by the system to copy default scripts to newly created users - which can help save some time.

My edited .profile looks like this:
Code:
# $FreeBSD: release/10.0.0/share/skel/dot.profile 199243 2009-11-13 05:54:55Z ed $
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#

# remove /usr/games if you want
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:$HOME/bin:/usr/local/lib/qt5/bin; export PATH

# Setting TERM is normally done through /etc/ttys.  Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm;     export TERM

BLOCKSIZE=K;    export BLOCKSIZE
EDITOR=vi;       export EDITOR
PAGER=more;     export PAGER

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV

if [ -x /usr/games/fortune ] ; then /usr/games/fortune freebsd-tips ; fi

With emphasis on:
Code:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:$HOME/bin:/usr/local/lib/qt5/bin; export PATH
My addition to this file was: :/usr/local/lib/qt5/bin/

Please note that each ":" marks the beginning of a new dir. address.

After a reboot, I was able to run qmake from my folders. I hope this helps.
 
Just stumbled across the same problem:

To add a new global variable for your bash (sh) first you have to use man sh, there, in the 4th paragraph we read:



So, we need to copy the .profile from the "/" to our home dir.(in case it doesn't exist) and edit that. I didn't have it, so I had to do:
sudo cp .profile /usr/home/<your_username>

My edited .profile looks like this:

# $FreeBSD: release/10.0.0/etc/root/dot.profile 199243 2009-11-13 05:54:55Z ed $
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:~/bin:/usr/local/lib/qt5/bin/
export PATH
HOME=/root
export HOME
TERM=${TERM:-xterm}
export TERM
PAGER=more
export PAGER


Please notice, that each ":" marks the beginning of a new dir. address. My addition to this file was: :/usr/local/lib/qt5/bin/

After a reboot, I was able to run qmake from my folders. I hope this helps.

No, don't use security/sudo when it's not needed. What you're doing creates a root owned .profile in your home directory and that's not what you want. You can copy root's .profile (/.profile is the same file just hardlinked) to your own directory with just:

cp /root/.profile ~/.profile
 
Don't copy root's files, you probably don't have access to it. There are a bunch of files in /usr/share/skel/ that are copied to a new user's home directory. For example /usr/share/skel/dot.profile ends up as ~/.profile. You can add your own or modify them so new user accounts get the right files.
 
Back
Top