Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rating: Thread Rating: 60 votes, 4.98 average. Display Modes
Old 02-09-2002, 12:02 AM   #1
Titanium Man
Guest
 
Posts: n/a
Best way to set environment?

I've been reading a lot here about using .cshrc or .tcshrc or ~/Library/init/tcsh/rc.mine to change environment prefs. I'll admit it, I'm confused. Which way is best? I thought setting prefs in rc.mine was best since you didn't get into the .tcshrc-file-being-read-before-the-.chsrc-file stuff, but I've seen other things recommended here too. What are your thoughts?

DOH! I just caught the tail end of the "Terminal mods" thread and it starts talking about this very thing, so sorry for posting this. I'd love to hear more ideas, though.

Last edited by Titanium Man; 02-09-2002 at 12:09 AM.
  Reply With Quote
Old 02-09-2002, 01:05 AM   #2
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
homer, TiMan,

perhaps what is needed is a real world test and examination.

i propose the following:

create a new user, and setup the vanilla tcsh shell as proscribed in the

/usr/share/init/tcsh/README

[ we'll do tcsh first, then bash ]

edit each script in the chain to broadcast it's name so that we can see the chain of command when we login and/or open new shell windows.

add the subsequent .[proscribedShellrc] to username's ~ and run again, examining behavior.

perhaps we will discover what we need to know about startup that is not evident in the doc's, or a bug will be uncovered, or otherwise, we will know what not to do.

suggestions?
mervTormel is offline   Reply With Quote
Old 02-09-2002, 01:54 AM   #3
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
MervTormel,

Here we go, finally the thread we wanted started, great!

Timan, good choice.

Can we slowly cover all of the .mine files?

What are the functions of and what goes inside:

aliases.mine
completions.mine
environment.mine
rc.mine
path

and then from:

~/.tcshrc
~/.login
~/.logout

Cheers...

Last edited by sao; 02-09-2002 at 02:03 AM.
sao is offline   Reply With Quote
Old 02-09-2002, 11:54 AM   #4
ebow
Triple-A Player
 
Join Date: Jan 2002
Location: 0x4D41
Posts: 105
I've been having trouble with stuff contained within environment.mine and rc.mine not working. However, aliases.mine and path seem to work just fine. So I'd love to see a thread that goes thru the whole tcshrc thang.
ebow is offline   Reply With Quote
Old 02-10-2002, 01:02 AM   #5
Titanium Man
Guest
 
Posts: n/a
Merv, I love your idea: the scientific approach, and sao, that would be GREAT if we could go over those files; it's been confusing me for a while. Ok, so I started up a new user and checked out /usr/share/init/tcsh/README. Now the FIRST part says to do this:

echo "source /usr/share/init/tcsh/rc" > ~/.tcshrc
echo "source /usr/share/init/tcsh/login" > ~/.login
echo "source /usr/share/init/tcsh/logout" > ~/.logout

but just AFTER that it says:

To do this system-wide, do the same instead to /etc/csh.cshrc, /etc/csh.login, and /etc/csh.logout.

So I checked out my /etc/csh.cshrc, /etc/csh.login, and /etc/csh.logout files, and they already had "source /usr/share/init/*" where * stands for rc in cshrc, login in chs.login, and logout in csh.logout. Hmm. Ok NOW the README says:

In order to customize tcsh:

mkdir ~/Library/init/tcsh

and create the following files there as necessary:

aliases.mine - shell aliases
completions.mine - completions
environment.mine - environment
rc.mine - run commands
path - command search path

Now don't get me wrong; I'm sure there are MANY ways to customize, but since I'm not even an OSX "poweruser" much less any kind of Unix wizard, I'm trying to find out the BEST way (even if it's not the easiest). Ebow, I don't know what's going on with your rc.mine or environment.mine. I haven't had any problems whatsoever, but the only thing in my rc. mine is my terminal prompt customization:

set prompt="%{\033[0;1;32m%}[%{\033[37m%}%t %n %{033[32m%}%{\033[33m%}%c3%{\033[32m%}]%{\033[0m%}%# "

and all I have in my environment.mine is that little thingy to make the autocomplete non case sensitive (and yes "little thingy" is the proper Unix term):

set complete=enhance

(I'm still not sure that's where it goes, but it works). Oh I just caught something; in the above examples of my rc.mine and environment.mine files those don't exist yet in my test user directory that I created to experiment with, only in my usual day to day user directory. So what now Dr Tormel? Is it pass me that butter knife and we'll see what makes this baby tick? (Sorry for such a long post)
  Reply With Quote
Old 02-10-2002, 01:36 AM   #6
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
sorry, gentlemen, my time's been usurped elsewhere and haven't been able to attend to this proposition. but i see TiMan has picked up the ball, so...

this may be a complete waste, but how about editing each script in the user's custom scriptage to broadcast it's name so that we can see the chain of command for the shell.

i think the objective of this is to see what is run on the initial shell window versus new shell windows and every command entered on the shell command line.

perhaps there may be some surprises.

e.g.
Code:
% cat .login
# ~/.login

echo "-----------------------------"
echo "well, here we are in ~/.login"
echo "-----------------------------"
echo ""

date

exit
something like that in all the .mine startup scripts.
mervTormel is offline   Reply With Quote
Old 02-10-2002, 08:53 AM   #7
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
mervTormel, great you are here, I look forward to your posts about this subject.

Please, allow me, I want just to give a little bit of information for beginners who don't know what we are talking about.

The shell is known as "login shell" when it is a shell which is not launched by another. For example, when I open the terminal window a new login shell is launched (in the default configuration of Terminal.app).

When we execute the command tcsh, it launches a new Shell which is not a login Shell.
We say it is an "interactive shell" when it has a prompt where to type commands.


The standard Starting files of /bin/tcsh :

When you login, the files are read in this order:

/etc/csh.cshrc (*)
/etc/csh.login
~/.tcshrc (*)
(~/.cshrc) (*)
~/.login
~/.history
~/.cshdirs
/etc/csh.logout
~/.logout

When the shell is not a login shell only the files marked (*) are read.

The file ~/.cshrc is read only if the file ~/.tcshrc is not found.
The files /etc/csh.logout and ~/.logout are read only when we exit the login shell.
The files ~/.history and ~/.cshdirs are not really configuration files but files that preserve constant data from one session to another.

In MacOS X, the files /etc/csh.cshrc , /etc/csh.login and /etc/csh.logout, call upon files located in /usr/share/init/tcsh/. These new files define a new hierarchy of starting files.

In all, we have the following files in this starting order

/etc/csh.cshrc
/usr/share/init/tcsh/rc
/usr/share/init/tcsh/environment
~/Library/init/tcsh/environment.mine
/usr/share/init/tcsh/tcsh.defaults
~/Library/init/tcsh/rc.mine
/usr/share/init/tcsh/aliases
~/Library/init/tcsh/aliases.mine
/usr/share/init/tcsh/completions
~/Library/init/tcsh/completions.mine
/etc/csh.login
/usr/share/init/tcsh/login
~/Library/init/tcsh/path
~/Library/init/tcsh/login.mine
~/.tcshrc
(~/.cshrc)
~/.login
~/.history
~/.cshdirs
/etc/csh.logout
/usr/share/init/tcsh/logout
~/Library/init/tcsh/logout.mine
~/.logout


The order these files are read, depends if the shell is a login shell or not.
(Some of these files are not read when the shell is not an interactive shell.)
Of course, we can customize the scripts to modify the order and behaviour.

My advice is to become familiar with the default, system-defined environment before making customizations (study). And customizations should be done in the .mine files (like aliases.mine), not in the startup files themselves.

For example we can copy /usr/share/init/tcsh/aliases to ~/Library/init/tcsh aliases.mine, customize aliases.mine and then check for any conflicts with the default environment.

We must make sure that our changes do not conflict with the system defined environment variables and aliases.
If you find that something is "wrong" in your environment, first remove your customizations and see if they are causing a conflict with the system-defined environment.

And using common sense if we want to modify path, we should add additional directories to the existing path and not redefine the path.

(Please, mervtormel, correct me if I wrote something wrong.)

Cheers...

Last edited by sao; 02-10-2002 at 10:05 AM.
sao is offline   Reply With Quote
Old 02-10-2002, 02:28 PM   #8
ebow
Triple-A Player
 
Join Date: Jan 2002
Location: 0x4D41
Posts: 105
Great idea, tagging each dot-file. I tagged the following files:

~/Library/init/tcsh/aliases.mine
~/Library/init/tcsh/completions.mine
~/Library/init/tcsh/environment.mine
~/Library/init/tcsh/path
~/Library/init/tcsh/rc.mine
~/.login
~/.tcshrc
/usr/share/init/tcsh/aliases
/usr/share/init/tcsh/tcsh.defaults
/usr/share/init/tcsh/rc
/usr/share/init/tcsh/environment
/usr/share/init/tcsh/login
/usr/share/init/tcsh/completions
/etc/csh.cshrc
/etc/csh.login

This is the order they show up when I start Terminal, or open a new terminal window:

/etc/csh.cshrc
/usr/share/init/tcsh/rc
/usr/share/init/tcsh/environment
/usr/share/init/tcsh/tcsh.defaults
~/Library/init/tcsh/rc.mine
/usr/share/init/tcsh/aliases
~/Library/init/tcsh/aliases.mine
/usr/share/init/tcsh/completions
~/Library/init/tcsh/completions.mine
/etc/csh.login
/usr/share/init/tcsh/login
~/Library/init/tcsh/path
~/.tcshrc
/usr/share/init/tcsh/rc
/usr/share/init/tcsh/tcsh.defaults
~/Library/init/tcsh/rc.mine
/usr/share/init/tcsh/aliases
~/Library/init/tcsh/aliases.mine
/usr/share/init/tcsh/completions
~/Library/init/tcsh/completions.mine
~/.login
/usr/share/init/tcsh/login
~/Library/init/tcsh/path

That's precisely the order, duplications and all. Notice that the following is not being processed:

~/Library/init/tcsh/environment.mine

I don't know what a "login shell" is, so I can't comment on that. Two other things I've noticed are that when I do a "source .tcshrc" which is the way I learned way back when to process changes to these dot-files, I get the following order:

~/Library/init/tcsh/rc.mine
/usr/share/init/tcsh/aliases
~/Library/init/tcsh/aliases.mine
/usr/share/init/tcsh/completions
~/Library/init/tcsh/completions.mine

When I "su" into my username from my prompt, I get the following:

/etc/csh.cshrc
/usr/share/init/tcsh/rc
/usr/share/init/tcsh/tcsh.defaults
~/Library/init/tcsh/rc.mine
/usr/share/init/tcsh/aliases
~/Library/init/tcsh/aliases.mine
/usr/share/init/tcsh/completions
~/Library/init/tcsh/completions.mine
~/.tcshrc
/usr/share/init/tcsh/rc
/usr/share/init/tcsh/tcsh.defaults
~/Library/init/tcsh/rc.mine
/usr/share/init/tcsh/aliases
~/Library/init/tcsh/aliases.mine
/usr/share/init/tcsh/completions
~/Library/init/tcsh/completions.mine

So it seems like everything's getting processed twice (and hence the long post - sorry!), except for environment.mine which isn't getting processed at all. I just checked the global environment file, and it has the "Read user's environment" statement, which looks proper. Nothing appears abnormal about the permissions or formatting of environment.mine.
Oh well, enough exploring for now.... If anyone has a flash of insight into my problem, perhaps having seen this before, I'd appreciate the feedback.

-ebow-
ebow is offline   Reply With Quote
Old 02-10-2002, 02:35 PM   #9
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
sao, thanks for the excellent post.

in a cursory examination, i see that

/usr/share/init/tcsh/rc

will only call

/usr/share/init/tcsh/environment

if it's the top most shell, interactive or an Xsession, and

if the shell is non-interactive, no calls are made to

/usr/share/init/tcsh/aliases
/usr/share/init/tcsh/completions


so, there are several branches taken depending on if it's the first shell, interactive or not, xsession or not, hmmmm, what else?

note: shell scripts are run in a subshell unless you use source or . commands to start the script.

let's continue to examine this and what is meant by login shells, non-login shells, non-interactive shells, sub-shells, and their ilk.


and does this illuminate anything about macubergeek's startup problem?

http://forums.macosxhints.com/showth...s=&postid=3644
mervTormel is offline   Reply With Quote
Old 02-10-2002, 02:45 PM   #10
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
doh!

ebow, you slipped in there right before my post.

excellent job. that's what i want to see ( without fiddling with my accounts

remember, the environment script is only run once, for the top shell, and that environment is inherited (?) by subsequent shells.

something nags at me about a bug in /usr/share/init/tcsh/environment that i fixed here for some version of tcsh.

eyeball that script and see that it makes the correct ref about your environment.mine.

edit: -ebow-, try this:

% exec tcsh -l

that'll get you a fresh login shell, like the first terminal window (?) perhaps you'll see your call to environment.mine ?

Last edited by mervTormel; 02-10-2002 at 02:52 PM.
mervTormel is offline   Reply With Quote
Old 02-10-2002, 03:06 PM   #11
ebow
Triple-A Player
 
Join Date: Jan 2002
Location: 0x4D41
Posts: 105
FWIW, here's the meaningful contents of my /usr/share/init/tcsh/environment:

Code:
setenv ENV_SET			# avoid repeat

umask 022			# files created are -rw-r--r--

##
# Read user's environment
##
if (-r "${tcsh_initdir}/environment.mine") then
  source "${tcsh_initdir}/environment.mine"
endif
The if...then...endif statements has exactly the same structure as any other such file.
ebow is offline   Reply With Quote
Old 02-10-2002, 03:11 PM   #12
ebow
Triple-A Player
 
Join Date: Jan 2002
Location: 0x4D41
Posts: 105
mervTormel -

No luck with the "exec tcsh -l" command. I get the same sequence as when opening a new window or starting terminal, but without *any* environment files.

[this message board software needs a good "hmm" face ]

Thanks for the ideas!
ebow is offline   Reply With Quote
Old 02-10-2002, 03:32 PM   #13
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
ebow, try this:

% unsetenv ENV_SET
% exec tcsh -V

...

unset the ENV_SET variable and exec the shell with verbosity on, then you can trace what happens in .../tcsh/rc when it checks ENV_SET


also, i am wrong about environment getting inherited in new shell windows.

for each new terminal window, i get

---
welp, here we are in ~/Library/init/tcsh/environment.mine
---

mervTormel is offline   Reply With Quote
Old 02-10-2002, 04:15 PM   #14
ebow
Triple-A Player
 
Join Date: Jan 2002
Location: 0x4D41
Posts: 105
Don't get too frustrated over obscure settings problems on a stranger's computer...

I tried unsetting the variable and doing a verbose exec. The part of interest went as follows:

Code:
if ( ! $?ENV_SET ) then
if ( -r "${default_tcsh_initdir}/environment" && ( $?prompt || $?XSESSION ) ) then
source "${default_tcsh_initdir}/environment"
echo "processing /usr/share/init/tcsh/environment"
processing /usr/share/init/tcsh/environment

[several blank lines]

setenv ENV_SET

umask 022

[several blank lines]

if ( -r "${tcsh_initdir}/environment.mine" ) then
source "${tcsh_initdir}/environment.mine"
endif
endif
else
The second time it gets to "if ( ! $?ENV_SET ) then" (because /usr/share/init/tcsh/rc has been called again) it just skips over the section (which makes sense). It seems like it wouldn't even print the "source "${tcsh_initdir}/environment.mine" line if it didn't intend to do it, so that means that environment.mine is getting sourced, but not getting sourced.

UPDATE/edit: The fact that the file never properly got sourced made me think there must be something wrong with the *file* itself, as opposed to the path, filename, contents, etc. So, I renamed environment.mine to ___.BACKUP, and then pasted the contents into a new textfile in BBEdit. I saved it with Unix line breaks, opened a new terminal window, and voila! It's in the loop.

Something that might be significant. The Finder reports that all files in ~Library/init/tcsh, except the new one, are "Apple SimpleText Document"s. Since pico, vi, BBEdit, and TextEdit opened them all the same (escape sequences made in vi the exception) I figured it was just report "text file" as "SimpleText Document". The fact that *every other* file worked properly further reinforced that notion. However, something must have been not quite right with the environment.mine file.

Thanks for prompting this exploration! I'm going to make sure all my files are "proper" unix text files now... While BBEdit can't create escape sequence characters (such as ^V^[ in vi) it seems to respect them, so I'm going to stick with that as my editor for at least my own tcsh settings files.

Last edited by ebow; 02-10-2002 at 04:26 PM.
ebow is offline   Reply With Quote
Old 02-10-2002, 04:37 PM   #15
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
not frustrated, but we're developing some good troubleshooting skills here.

how to investigate this further...

what happens when you just:

% source "${tcsh_initdir}/environment.mine"

how about starting a verbose sub-shell and running it...

% tcsh -V
...
argle-bargle
...

% source "${tcsh_initdir}/environment.mine"
mervTormel is offline   Reply With Quote
Old 02-10-2002, 04:42 PM   #16
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
ebow wrote:
--
UPDATE/edit: The fact that the file never properly got sourced made me think there must be something wrong with the *file* itself, as opposed to the path, filename, contents, etc. So, I renamed environment.mine...
--

way to go. that's what i was poking at you about. get down in there and find the truth. investigate the atomic elements of a thing and the skills are developed in course.

now, where were we?

regards, mt
mervTormel is offline   Reply With Quote
Old 02-11-2002, 12:04 AM   #17
Titanium Man
Guest
 
Posts: n/a
Wow, I missed a lot while I was asleep! Great work ebow! So, what does all this mean? If source /usr/share/init/tcsh/* is already in all the appropriate files (/etc/csh.cshrc, /etc/csh.login, and /etc/csh.logout) as per the instructions for system wide use in share/init/tcsh/README, we should be set just modifying the .mine files right (not creating ~/.tcshrc, ~/.login, and ~/.logout files)? Unless we're on a big network and DON'T want to make system wide changes? (Sorry I'm really not that dense, just new to Unix).
  Reply With Quote
Old 02-11-2002, 12:16 AM   #18
ebow
Triple-A Player
 
Join Date: Jan 2002
Location: 0x4D41
Posts: 105
Yeah, aside from figuring out about text file formatting, I got the impression that setting up a ~/.tcshrc file was redundant. I'm not sure about the .login and .logout as I have no (current) use for them, but they seem to be in the same boat.

Last edited by ebow; 02-11-2002 at 12:20 AM.
ebow is offline   Reply With Quote
Old 02-11-2002, 07:55 AM   #19
sao
Moderator
 
Join Date: Jan 2002
Location: Singapore
Posts: 4,237
From the tcsh manual pages online in:

http://www.tcsh.org/Home

<< A login shell begins by executing commands from the system files /etc/csh.cshrc and /etc/csh.login.
It then executes commands from files in the user's home directory: first ~/.tcshrc (+) or, if ~/.tcshrc is not found, ~/.cshrc, then ~/.history (or the value of the histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the value of the dirsfile shell variable) (+). >>

But also says:

<< Users who need to use the same set of files with both csh(1) and tcsh can have only a ~/.cshrc which checks for the existence of the tcsh shell variable (q.v.) before using tcsh-specific commands, or can have both a ~/.cshrc and a ~/.tcshrc which sources (see the builtin command) ~/.cshrc.>>

Well, the point here is to say that it's possible to have both " both a ~/.cshrc and a ~/.tcshrc which sources (see the builtin command) ~/.cshrc." as explained above.

As long as your ~/,tcshrc "source ~/.cshrc".

At the same time, much better to keep it simple and use ~Library/init/tcsh and ~/.cshrc

About ~/.login and ~/.logout the manual says:

<<Commands like stty(1) and tset(1), which need be run only once per login, usually go in one's ~/.login file.>>

<<~/.login
Read by login shells after ~/.tcshrc or ~/.history. The shell may be compiled to read ~/.login before instead of after ~/.tcshrc and ~/.history; see the version shell variable. >>

<<~/.logout
Read by login shells at logout after /etc/csh.logout or its equivalent.>>

I don't use this files myself but just as information:

~/.login file
Hardly anyone needs to have a personal ".login" file. If you do need one, put commands inside which only need to happen at login time.

What Goes Inside a ".login" File?

You can define a special prompt which is seen only in your login window.
You can run special file maintenance commands which only need to happen once, when you login.

~/.logout file
You use if you want to perform special commands at logout time

What Goes Inside a ".logout" File?

Remove unnecessary object files from your login directory.
Remove unsafe entries.


Cheers...

Last edited by sao; 02-11-2002 at 08:32 AM.
sao is offline   Reply With Quote
Old 02-11-2002, 09:36 AM   #20
pmccann
Major Leaguer
 
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
Let me just bow before the true hard-liners here: sao, and ebow in particular. Your stamina, resolve resourcefulness are enormously impressive!

One clarification: sao wrote...

Quote:
~/.login file
Hardly anyone needs to have a personal ".login" file. If you do need one, put commands inside which only need to happen at login time.

I disagree, and feel that pretty much everyone *should* have a .login file, but instead they tend to creatively abuse their ~/.cshrc or ~/.tcshrc or ~/Library/init... (you get the idea!). I'm far from immune to this disease. As you point out, the .login is for commands that only need be executed *once* per "session" (ie once for the set of processes initiated by and including the login shell. Sorry, that's an ugly sentence!).

So what sort of things need to be executed only once per session? Well, definitely any environment declarations. So if you've got any "setenv" lines in your .cshrc or (I give up!) other equivalent file you're guilty as charged; not that it really matters, but if we're going to be doing things the "right" way... Of course the whole idea of an environment is that it propagates to subprocesses, including shells in shells etc.

Anyway, as a dirty old recalcitrant I'm going to take a lot of convincing to give up my simple ".cshrc and .login" twosome. Full stop. I appreciate the intent behind the separation of files into environment/login/logout/rc/completions/aliases, but to be honest, it ain't gonna happen! I'll just separate out the bits and pieces within those files.

Familiarity breeds content! (isn't that the saying? Oh...)

Ignore as necessary...

Paul
pmccann is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:43 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.