# bash rules, tcsh lacks... except for this...



## cello (Nov 6, 2002)

This is a very strange problem that I'm having (this is running Jaguar).  It seems as though when using bash, environment variable bindings are simply not recognized by any other command.  For example, if you use cvs, and want to set the CVSROOT variable, typing CVSROOT=:ext:user@foo.com:/foo/bar will allow you to see the variable when you echo $CVSROOT, but for some reason the cvs command doesn't recognize that it's there:

cvs update: No CVSROOT specified!  Please use the `-d' option
cvs [update aborted]: or set the CVSROOT environment variable.

This doesn't only apply to cvs, it also applies to every other program that uses environment variables _for example, setting the DISPLAY variable doesn't get recognized when you try to run something on an XServer.  There are other examples, but I'm sure you can just trust me that it's not an issue with these commands and instead an issue with, well, something else.

Anyhow, running tcsh will resolve these problems, but tcsh sucks.  On another note, perhaps I would run tcsh if it did command completions and directory completions correctly on Darwin.  Does anyone know of a patch that makes that stuff work properly?


----------



## jwalk76 (Nov 6, 2002)

this is just a guess.  is it possible that you need to quote the variable when using it within a command?

EDIT:
using the bash shell, i just created a new user in this manner:

NEWUSER='cleetus'
NEWDIR='/tmp'
useradd -d $NEWDIR $NEWUSER

the newly created user was cleetus with the home directory in /tmp.  i should mention that i did this on my Slackware Linux box as i don't have access to my Mac right now, but i would assume that bash would behave the same on both...?  obviously not.  i'll try my Mac when i get home from work.


----------



## cello (Nov 6, 2002)

hmm - I tried putting them in quotes, in double quotes, and in no quotes and the same problem occurs.

Let me know if it works on your mac os x box.


----------



## jwalk76 (Nov 6, 2002)

i'm still using 10.1.5, so i don't have bash.  i tested it using the generic "sh", and everything worked fine.  i've never used CVS, so i'm not familiar with the commands.  i did read in the man page that  the path specified with the -d flag overrides the value of the $CVSROOT environment variable.  even though i don't think it should matter, try setting a different variable to the path and passing the new variable to the -d flag.


----------



## al451 (Nov 7, 2002)

Short answer to the original poster: you need to "export" your shell variable to the environment like this:

  export CVSROOT

to have the effect you're trying to get.

If a shell variable (like CVSROOT) is "exported", then whenever you set its value, the corresponding value is set in the process's environment. Child processes (like cvs) inherit the environment of the parent process, but they can't know anything about ordinray shell variables. So if you don't "export" your variable, child processes won't see it.

Some shell variables are exported for you, either by bash itself or by its startup scripts (bashrc, bash_profile, whatever).

In bash, you can see which shell variables are "exported" to the environment with the command "export -p".

Any change to the value of "exported" variables will be passed to the shell process's environment, and so will be visible in the environment of child processes.

In a traditional shell you might set CVSROOT like this:

  CVSROOT=/path/to/cvsroot
  export CVSROOT

Bash lets you do both at once:

    export CVSROOT=/path/to/cvsroot

but note that you only have to "export" once; now that CVSROOT has been exported, future changes to its value will still be reflected in the process environment.

You can "unexport" variables as well  (for that, you can see the documentation!).


----------

