Thread: Environment variables

Environment variables

From
Roy MacGregor Paterson
Date:
Thanks to Michael Grant for getting me started (previous question).

Here's the conceptual pothole I'm currently in...

I want to set up the PATH variable for psql. I might even understand why.

I've got a .tcshrc file in my home directory.

I know how to modify the .tcshrc file to include the relevant line...
"setenv PATH /usr/local/psql/bin"

However, .tcshrc already has a PATH variable which I don't want to lose...
"setenv PATH "$PATH":/Library/MySQL/bin"

So, can I just add the new line to the file? If so, how do psql and
MySQL know which is which, given that they have the same name?

Or, are they mutually incompatible - I can have one or the other but not both?

Or, are multiple PATH variables traversed until something makes sense
to whatever it is that reads them?

In my csh.login file I have the following PATH variable...
"setenv PATH "/bin:/sbin:/usr/bin:/usr/sbin""

...and if I execute the terminal command "echo $PATH" I get...
"/bin:/sbin:/usr/bin:/usr/sbin:/Library/MySQL/bin"

...from this I deduce that I may be able to concatenate the paths in
.tcshrc into something like...
"setenv PATH "$PATH":/Library/MySQL/bin:/usr/local/psql/bin"
...is this correct?

Why is the syntax of these PATH variables different anyway? Is this
something specific to each of those programs or does
csh/tcsh/unix/macos allow two different syntaxes (syntaxi?) for the
setenv command (i.e. is setenv an attribute of tcsh or of psql and
MySQL)?

Yup, I don't have the O'Reilly book "csh and tcsh". It's nearly 1am
in London and the shops are closed. As ever, the two books that I do
have are telling me just enough to get me into trouble and not enough
to get me out again.

What websites should I be looking at to answer these kind of
questions without flashing the cash? Apple.com Support just shrugs
when I enter tcsh as a query.

TIA
Roy
--
--------------------
Roy MacGregor Paterson
MacGregorTech

t: +44 (0) 20 7584 7891
f: +44 (0) 20 7589 6223
m: +44 (0) 7803 163 938
w: www.macgregortech.com
e: roy@macgregortech.com
--------------------

Re: Environment variables

From
Bruno LEVEQUE
Date:
Hi Roy,


Roy MacGregor Paterson wrote:

> Thanks to Michael Grant for getting me started (previous question).
>
> Here's the conceptual pothole I'm currently in...
>
> I want to set up the PATH variable for psql. I might even understand why.
>
> I've got a .tcshrc file in my home directory.
>
> I know how to modify the .tcshrc file to include the relevant line...
> "setenv PATH /usr/local/psql/bin"
>
> However, .tcshrc already has a PATH variable which I don't want to
> lose...
> "setenv PATH "$PATH":/Library/MySQL/bin"
>
> So, can I just add the new line to the file? If so, how do psql and
> MySQL know which is which, given that they have the same name?
>

In the below line you have in logical write : PATH=PATH+/Library/MySQL/bin

So if you add another line like : setenv PATH "$PATH":/usr/local/psql/bin
You'll take what you want. ie (in logical write)
PATH=PATH+/usr/local/psql/bin
or, if we look the contain of PATH (in logical write)

PATH=/bin+/sbin+/usr/bin+/usr/sbin+/Library/MySQL/bin+/usr/local/psql/bin

It's what you want


> Or, are they mutually incompatible - I can have one or the other but
> not both?
>
> Or, are multiple PATH variables traversed until something makes sense
> to whatever it is that reads them?
>
> In my csh.login file I have the following PATH variable...
> "setenv PATH "/bin:/sbin:/usr/bin:/usr/sbin""
>
> ...and if I execute the terminal command "echo $PATH" I get...
> "/bin:/sbin:/usr/bin:/usr/sbin:/Library/MySQL/bin"
>
> ...from this I deduce that I may be able to concatenate the paths in
> .tcshrc into something like...
> "setenv PATH "$PATH":/Library/MySQL/bin:/usr/local/psql/bin"
> ...is this correct?
>
Yes

> Why is the syntax of these PATH variables different anyway? Is this
> something specific to each of those programs or does
> csh/tcsh/unix/macos allow two different syntaxes (syntaxi?) for the
> setenv command (i.e. is setenv an attribute of tcsh or of psql and
> MySQL)?
>
setenv is a (t)csh command.

In you csh.login you have a minimal value
(/bin:/sbin:/usr/bin:/usr/sbin). Just where to find system commands, and
in your .tcshrc you have an "user" value. Like this each user can take a
different PATH.

> Yup, I don't have the O'Reilly book "csh and tcsh". It's nearly 1am in
> London and the shops are closed. As ever, the two books that I do have
> are telling me just enough to get me into trouble and not enough to
> get me out again.
>
> What websites should I be looking at to answer these kind of questions
> without flashing the cash? Apple.com Support just shrugs when I enter
> tcsh as a query.


Sorry, I don't know

> TIA
> Roy


Bruno

--
Bruno LEVEQUE
System Engineer
SARL NET6D
bruno.leveque@net6d.com
http://www.net6d.com



Re: Environment variables

From
Roy MacGregor Paterson
Date:
Hi Bruno,

Thanks: my .tcshrc works with this...

setenv PATH "$PATH":/Library/MySQL/bin
setenv PATH "$PATH":/usr/local/bin
setenv PATH "$PATH":/usr/local/pgsql
setenv PATH "$PATH":/usr/local/pgsql/bin

...so now I get this response...
[MacGregor:/Users/roy] postgres% pg_ctl  -D /usr/local/pgsql/data start
postmaster successfully started
[MacGregor:/Users/roy] postgres% LOG:  database system was shut down
at 2003-11-22 12:06:33 GMT
LOG:  checkpoint record is at 0/805FB4
LOG:  redo record is at 0/805FB4; undo record is at 0/0; shutdown TRUE
LOG:  next transaction id: 490; next oid: 16977
LOG:  database system is ready


OK. Now I'm trying to get the PGDATA environment variable to work.
I've tried each the following lines in . tcshrc one at a time...
setenv PGDATA "$PGDATA":/usr/local/pgsql
setenv PGDATA "$PGDATA":/usr/local/pgsql/data
setenv PGDATA /usr/local/pgsql
setenv PGDATA /usr/local/pgsql/data
setenv $PGDATA /usr/local/pgsql
setenv $PGDATA /usr/local/pgsql/data

...and always get this response...
[MacGregor:/Users/roy] postgres% pg_ctl start
pg_ctl: no database directory or environment variable $PGDATA is specified
Try 'pg_ctl --help' for more information.
[MacGregor:/Users/roy] postgres%

...so what's going on?

regards,
Roy
--
--------------------
Roy MacGregor Paterson
MacGregorTech

t: +44 (0) 20 7584 7891
f: +44 (0) 20 7589 6223
m: +44 (0) 7803 163 938
w: www.macgregortech.com
e: roy@macgregortech.com
--------------------

Re: Environment variables

From
Bruno LEVEQUE
Date:
Hi Roy,

Fisrt, the good syntax is

setenv PGDATA "/usr/local/pgsql/data" (with or without "")

Because PGDATA is a variable with only one value
(/usr/local/pgsql/data), so before this setenv, PGDATA is empty and
after it should take only /usr/local/pgsql/data.

You use $PGDATA when you want to know wath the variable PGDATA contains

for example :

setenv PGDATA anywhere/your/data/are
echo $PGDATA   ->>>>>>>>>>>>> in the screen you take anywhere/your/data/are



Second, you must give the path where are you data, ie where you say to
initdb.

Were you used initdb ? (initdb -D DATADIR)

BR

Bruno



Roy MacGregor Paterson wrote:

> Hi Bruno,
>
> Thanks: my .tcshrc works with this...
>
> setenv PATH "$PATH":/Library/MySQL/bin
> setenv PATH "$PATH":/usr/local/bin
> setenv PATH "$PATH":/usr/local/pgsql
> setenv PATH "$PATH":/usr/local/pgsql/bin
>
> ...so now I get this response...
> [MacGregor:/Users/roy] postgres% pg_ctl  -D /usr/local/pgsql/data start
> postmaster successfully started
> [MacGregor:/Users/roy] postgres% LOG:  database system was shut down
> at 2003-11-22 12:06:33 GMT
> LOG:  checkpoint record is at 0/805FB4
> LOG:  redo record is at 0/805FB4; undo record is at 0/0; shutdown TRUE
> LOG:  next transaction id: 490; next oid: 16977
> LOG:  database system is ready
>
>
> OK. Now I'm trying to get the PGDATA environment variable to work.
> I've tried each the following lines in . tcshrc one at a time...
> setenv PGDATA "$PGDATA":/usr/local/pgsql
> setenv PGDATA "$PGDATA":/usr/local/pgsql/data
> setenv PGDATA /usr/local/pgsql
> setenv PGDATA /usr/local/pgsql/data
> setenv $PGDATA /usr/local/pgsql
> setenv $PGDATA /usr/local/pgsql/data
>
> ...and always get this response...
> [MacGregor:/Users/roy] postgres% pg_ctl start
> pg_ctl: no database directory or environment variable $PGDATA is
> specified
> Try 'pg_ctl --help' for more information.
> [MacGregor:/Users/roy] postgres%
>
> ...so what's going on?
>
> regards,
> Roy


--
Bruno LEVEQUE
System Engineer
SARL NET6D
bruno.leveque@net6d.com
http://www.net6d.com



Re: Environment variables

From
Michael Grant
Date:
On Nov 22, 2003, at 6:59 AM, Roy MacGregor Paterson wrote:

> ...so what's going on?

You might want to joint the X-Unix list to discuss Unixy stuff among
other Macheads. See <http://www.themacintoshguy.com/lists/X.html>

Michael

--
The government doesn't want you to know... e-mail doesn't work. At all.
It's a scientific impossibility.


Re: Environment variables

From
"Anis W. Nugroho"
Date:
Hi Roy,
I'm not a (t)csh lover, but just bash lover.
OK in bash, if I want an environment variable that set in the
.bashrc to be recognized through out the session, I must use
export ENV_VAR_NAME
because that variable only recognized during the live of
.bashrc.
For (t)csh, maybe you can find the similarities to that feature.
To be sure, after editing .tcshrc or .cshrc, login to another
session. Then display all the environment variables you have.
For bash, I usually type 'set'.
Access man tcsh or man csh for the detailed feature.
Hope this works for you.
Cheers,
Anis WN
________________________________
15 Mbytes Free Web-based and  POP3
Sign up now: http://www.gawab.com

Environment variables SOLVED

From
Roy MacGregor Paterson
Date:
Just a note to say thanks to all who chipped in on this one.

I couldn't get Environment Variables to behave themselves, but I've
since discovered the downloadable PostgreSQL manuals, and bought (and
read ;-) the O'Reilly's:

Using csh and tsch
Unix Power Tools
Learning Unix for Mac OS X

I had solved the PATH environment variable for pg_ctl: it's in the
file .tcshrc, but I just could not get PGDATA to work.

Eventually figured out that, as it was the last line in the .tcshrc
file, it couldn't be seen by setenv because it wasn't followed by a
line feed. This was using BBEdit with .tcshrc defined as a unix file
type.

Roy
--
--------------------
Roy MacGregor Paterson
MacGregorTech

t: +44 (0) 20 7584 7891
f: +44 (0) 20 7589 6223
m: +44 (0) 7803 163 938
w: www.macgregortech.com
e: roy@macgregortech.com
--------------------

OT: Re: Environment variables SOLVED

From
Michael Glaesemann
Date:
On Wednesday, December 3, 2003, at 05:15 PM, Roy MacGregor Paterson
wrote:
> I couldn't get Environment Variables to behave themselves, but I've
> since discovered the downloadable PostgreSQL manuals, and bought (and
> read ;-) the O'Reilly's:
>
> Using csh and tsch
> Unix Power Tools
> Learning Unix for Mac OS X
<snip/>
> Eventually figured out that, as it was the last line in the .tcshrc
> file, it couldn't be seen by setenv because it wasn't followed by a
> line feed. This was using BBEdit with .tcshrc defined as a unix file
> type.

Just to let you know (as it's something I'm learning right now!), the
default shell in Panther is bash, rather than tcsh. With my lack of
Unix knowledge, it took me quite by surprise when I found setenv no
longer worked!

By the way, does "Learning Unix for Mac OS X" cover bash? "Mac OS X in
a Nutshell" covers tcsh in pretty good detail, but not much at all on
bash. (I see "Mac OS X Panther in a Nutshell" is due out in March.)

Getting to love my Bourne Again SHell,

Michael Glaesemann
grzm myrealbox com


Re: OT: Re: Environment variables SOLVED

From
Michael Grant
Date:
On Dec 3, 2003, at 5:26 AM, Michael Glaesemann wrote:

> By the way, does "Learning Unix for Mac OS X" cover bash? "Mac OS X in
> a Nutshell" covers tcsh in pretty good detail, but not much at all on
> bash. (I see "Mac OS X Panther in a Nutshell" is due out in March.)

The Panther edition of Mac OS X Unleashed is supposed to be out next
week. If it lives up to the first two editions, it'll be the only
MacNix book you ever need. Till 10.4 "Ocelot" comes out and zsh becomes
the default shell, anyway.

Michael


--
Ukončete výstup a nástup, dveře se zavírají.