how to view environment variables

Chuck Robey chuckr at
Sun Jun 15 17:01:39 UTC 2008

Hash: SHA1

Chris Whitehouse wrote:
> RW wrote:
>> On Sun, 15 Jun 2008 00:27:10 +0100
>> Chris Whitehouse <cwhiteh at> wrote:
>>> Hello,
>>> sysutils/fusefs-ntfs/files/README.FreeBSD refers to various
>>> environment variables, eg UBLIO_BLOCKSIZE and others. How do I find
>>> out what they are set to? set and printenv don't find them. I'm using
>>> standard csh and FreeBSD 7.0-STABLE, fuse.ko is loaded and ntfs-3g
>>> works except it seems very slow.
>> If you didn't set them, they probably aren't set. You'll need to
>> consult the fusefs-ntfs documentation (or source) to find the default
>> value.
> I think this explains part of my confusion. If the variables are not set
> ntfs-3g assumes some defaults (in README.FreeBSD) but doesn't set them
> as environment variables. I thought ntfs-3g would actually set them. I
> still don't know how to view them when I have explicitly set them, as
> per previous reply to Robert Huff.
> eco# env UBLIO_BLOCKSIZE=65536 ntfs-3g /dev/ad0s1 /ad0s1
> eco# setenv |grep UBLIO
> eco#

I just picked up on this ... environmental variables are part of the private
environment of programs.   Those variables are given to any child programs.  If
the programs are shells, shells specialize in creating child programs, so all
those environmental variables get given to the children.  A filesystem doesn't
create children, it just organizes the storage and presentation of disk data, so
when you set a environmental variable to a filesystem, it may react to that
variable if it is programmed that way, but it doesn't send it anywhere.  If you
want to see the variable in your shell, then you must tell the shell to set it
in it's environment.  For a sh-like shell, you would do something like:

export UBLIO_BLOCKSIZE=65536

For a csh-like shell, use:

setenv UBLIO_BLOCKSIZE 65536

(Notice that a csh-like shell DOESN'T use the "=").  Your filesystem prog is
being told of your variable above, but your attempt to see it is misguided.
There was a way to see the information, using the e option to ps, but it was
always a security problem, so it seems like that was removed from FreeBSD (it's
probably controlled by a sysctl).  I think it still works in most linuxes.
Reading the variables is very easy to do with the "env" program, where if you
give it no  args, it repeats all the variables.  Try it.  It works for all
shells, unlike your "setenv", because it's an actual program (/usr/bin/env).
setenv is, for a csh-like shell, a shell built-in, not a real program.

The way it goes to programs is via 3 variables given to every program.  They
are, in the order they're presented:

1- argc, which means the number of parameters given to the program by the shell
2- argv, a list of string pointers, to program parameters
3- envp, a list of string pointers, to name=value pairs, for all environmental
         variables given to each program.

Those names are only the commonly used names, they may be changed completely at
will, because the system only gives the info in the order I gave, and doesn't
associate the info with any names.  Your program needs to associate some names
to the parameters so that you can manipulate them, and using these names is a
good idea so as not to confuse other programmers, just don't get the idea that
those names have any real magic meaning on their own.  I could write a program
using manny, moe, and jack as the names of the 3 items given to a program, and
(beyond making things confusing) that program would work just fine.

Writing a small program that annouces the arguments count, and prints all of the
parameters, and all of the env. variables, makes a fine beginners first program.

> Chris
>> _______________________________________________
>> freebsd-questions at mailing list
>> To unsubscribe, send any mail to
>> "freebsd-questions-unsubscribe at"
> _______________________________________________
> freebsd-questions at mailing list
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe at"

Version: GnuPG v2.0.4 (FreeBSD)
Comment: Using GnuPG with Mozilla -


More information about the freebsd-questions mailing list