PDA

View Full Version : tcsh funkiness


lancelot183
01-28-2002, 08:46 PM
what happened here?

Welcome to Darwin!
tcsh_initdir: Undefined variable.
>

anybody know? thanks!! it's not a huge deal, because i'm using bash, but i'm curious... :D

mervTormel
01-28-2002, 08:58 PM
i suspect that bash is running through your startup scripts and one of these contains references to, or directly calls, the tcsh init scripts in your home dir.

check ~/.profile and for your bash startup scripts calling a tcsh startup script.

read the bash man pages about verbose mode

open a new terminal window and

$ exec bash -v

perhaps that will uncover the problem script.

let us know.

lancelot183
01-28-2002, 09:07 PM
nice thought... but no cigar.

sorry, i didn't mention that the reason i installed bash was because of this strange "tcsh_initdir undefined" thing.

verbose execution of bash yields nothing.
also, i don't seem to have a .profile... is that bad?

thanks!

mervTormel
01-28-2002, 09:25 PM
i suspect that you may have installed bash, but are still running a fractured tcsh installation in the terminal app.

show us some more info

show us the result of these commands:

> echo $version

> echo $SHELL

lancelot183
01-28-2002, 09:35 PM
bash2.05 lancelot@localhost ~ % echo $version

bash2.05 lancelot@localhost ~ % echo $SHELL
/bin/tcsh

there 'tis.

one more thing: i know i've got both installed. but... i want to be able to switch between them without a big deal.

when i tell Terminal to use tcsh, i get the tcsh_initdir undefined thing.
bash works fine.

make any sense?

mervTormel
01-28-2002, 09:45 PM
o i c

i thought you were running bash and getting the tcsh_initdir error. sheesh.

you have a fractured tcsh installation.

read and follow the instructions in the readme from the tcsh init bucket

% ll /usr/share/init/tcsh/
total 40k
-rw-r--r-- 1 root wheel 952 Sep 2 20:35 README
-rw-r--r-- 1 root wheel 892 Sep 2 20:35 aliases
-rw-r--r-- 1 root wheel 9.4k Sep 2 20:35 completions
-rw-r--r-- 1 root wheel 433 Sep 2 20:35 environment
-rw-r--r-- 1 root wheel 701 Sep 2 20:35 login
-rw-r--r-- 1 root wheel 395 Sep 2 20:35 logout
-rw-r--r-- 1 root wheel 1.9k Sep 2 20:35 rc
-rw-r--r-- 1 root wheel 2.3k Sep 2 20:35 tcsh.defaults

lancelot183
01-28-2002, 10:38 PM
<sigh> that came really close, but no dice...

i read the README and configured tcsh back... i now have

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

in ~/Library/init/tcsh

also, it sucessfully made ~/.tcshrc, ~/.login, and ~/logout. yet... it still does this when i try to run tcsh as the main shell in Terminal:

tcsh_initdir: Undefined variable.
>

heh.. on a sidenote, i just noticed that if you don't select "Use Default Shell" in the Terminal prefs, it doesn't say "Welcome to Darwin!" hm. anyhoo...

any clearer? or still mud?

thanks for your time!

mervTormel
01-28-2002, 11:03 PM
okay, let's look at this then...


% ll /etc/csh*
-rw-r--r-- 1 root wheel 31 Sep 2 20:35 /etc/csh.cshrc
-rw-r--r-- 1 root wheel 34 Sep 2 20:35 /etc/csh.login
-rw-r--r-- 1 root wheel 35 Sep 2 20:35 /etc/csh.logout

% cat /etc/csh.cshrc
source /usr/share/init/tcsh/rc

% less /usr/share/init/tcsh/rc
##
# TCSH Expanded C-Shell INITIALIZATION FILE
#
<snip>

set default_tcsh_initdir = /usr/share/init/tcsh
set user_tcsh_initdir = ~/Library/init/tcsh

if (-r "${user_tcsh_initdir}") then
set tcsh_initdir = "${user_tcsh_initdir}"
else
set tcsh_initdir = "${default_tcsh_initdir}"
endif
...


if your tcsh startup doesn't look like this, that could be it.

if it does look like this, then we need to find where the ref to tcsh_initdir poops out.

try

% exec tcsh -V

and follow this up to where the undefined error is and let us know.

BTW, the last part of this could get very long because it processes your command history file, so page up to the beginning of -V run and follow from there.

lancelot183
01-28-2002, 11:36 PM
is it bad if i don't have a csh.cshrc? :(

mervTormel
01-28-2002, 11:44 PM
urp!

yep. well, er, no, not bad qua bad, but it's problematic if you want tcsh to work well.

here are the ownership, permissions, and contents of csh.cshrc


% ll /etc/csh.cshrc
-rw-r--r-- 1 root wheel 31 Sep 2 20:35 /etc/csh.cshrc

% cat /etc/csh.cshrc
source /usr/share/init/tcsh/rc


you should prolly have csh.login and csh.logout, too.

that should get you started at solving this problem. let us know how you do.

lancelot183
01-29-2002, 12:00 AM
ok, i made the file... but i used the GUI to c&p the contents of rc into it... and now it's 1960 bytes... whereas yours says 31...

'scuse my newbiness: what's cat and source do? i tried doin what you showed in our code, but it didn't quite work. is that line break s'posed to be there?

btw, the top of my rc file looks the same as yours.

i think we're gettin close...

lancelot183
01-29-2002, 12:43 AM
alright, now that i have a csh.cshrc file... and it looks exactly like the tcsh/rc file... when i try to run tcsh i get this:

[Process was terminated by signal 11]

any ideas?

mervTormel
01-29-2002, 12:45 AM
something's wrong with 1960 bytes.

read thru all of this first and try these things:


% unset noclobber
% sudo echo "source /usr/share/init/tcsh/rc" > /etc/csh.cshrc
% sudo chmod u=rw,go=r /etc/csh.cshrc
% sudo chown root:wheel /etc/csh.cshrc


sudo is gonna ask for your password. i don't know how you got your GUI editor to save /etc/csh.cshrc

what GUI editor did you use?

cat = concatenate files and print to standard output, that is, display file contents

source = tcsh's builtin command to tell the shell to read and execute commands in a file

you can read documentation about commands in the infamous man pages

% man cat
% man tcsh

i don't know which line break you're referring to, alas.

sudo - execute command as other user
echo - write args to stdout
chmod - change access modes (permissions)
chown - change owner:group

okay, now dig into those man pages

mervTormel
01-29-2002, 12:49 AM
Originally posted by lancelot183
alright, now that i have a csh.cshrc file... and it looks exactly like the tcsh/rc file... when i try to run tcsh i get this:

[Process was terminated by signal 11]

any ideas?

% exec tcsh -V

will spit back every line the shell executes. the last one may have caused your sigterm 11.

some shell startup code is protected and it must run without error or die hard. what you got is the die hard scenario.


at this point, you need to get that /etc/csh.cshrc proper, then we can approach the remaining issues

lancelot183
01-29-2002, 01:07 AM
bash2.05 lancelot@localhost ~ % unset noclobber
bash2.05 lancelot@localhost ~ % sudo echo "source /usr/share/init/tcsh/rc" > /etc/csh.cshrc
bash: /etc/csh.cshrc: Permission denied

this is most odd.

thanks for the explanations of the commands... i asked before i thought to do a "whatis" on 'em, or a man lookup. :D
i'm slowly but surely gettin the hang of this UNIX shtuff... thanks very much for your patience.

do you use AOLIM? that might be faster... if you want to. my s/n is scapegoat51 (it's in my profile, of course, but i figure those extra clicks can be put to better use elsewhere )

lancelot183
01-29-2002, 01:36 AM
does this look like an endless loop to you? goto:
http://www.bonnvie.com/~lroggy/shtuff/tcshoutput.txt

that's what i got when i did exec tcsh -V.

not sure what that tells us, but...

mervTormel
01-29-2002, 01:38 AM
re: AOLIM, um, no

sorry, i can't seem to perform that sudo echo either. i don't understand that. and i want to emphasize this important point: test your code, and don't trust any given to you until you consider what it does.

so, use pico to edit that /etc/csh.cshrc

% sudo pico /etc/csh.cshrc

control-k (kill) all lines in that file and paste in this:

source /usr/share/init/tcsh/rc

control-x to quit, answer yes to the save prompt

then be sure to chmod, chown that puppy (sudo'd of course)

then open a new terminal (command-n) window and % exec tcsh

boy, that sure is wonky. i regret that this has been wonky for you. i'll try and find why that echo redirect (>) is so wonky.

your humble wonker,

-mt

mervTormel
01-29-2002, 01:43 AM
Originally posted by lancelot183
does this look like an endless loop to you? goto:
http://www.bonnvie.com/~lroggy/shtuff/tcshoutput.txt

that's what i got when i did exec tcsh -V.

not sure what that tells us, but...

yep. loopy. yer tcsh install is hosed.

BUT, this is a good excersise for sleuthing and using some common commands.

let's keep digging. get that csh.cshrc script correct, then we can proceed.

it should look like this when you're done



% ll /etc/csh.cshrc
-rw-r--r-- 1 root wheel 31 Sep 2 20:35 /etc/csh.cshrc

% cat /etc/csh.cshrc
source /usr/share/init/tcsh/rc

lancelot183
01-29-2002, 01:49 AM
ok, i understand things better now.

first, i thought csh.cshrc was supposed to be an exact duplicate of tcsh/etc. little did i know... so, that's fixed. now my csh.cshrc file is right.
however... it's still dropping out with a sigterm 11. (whatever that means...)

also, to answer your earlier question about GUI text editors:
i use BBEdit 6.1 Lite. and all i did was use "open [pathto rc]" to open that folder in the Finder, and then opened rc in BBEdit, then c&p'd it to pico. which, as i know see, was not what you were tryin to get me to do. :D

trial and error...

mervTormel
01-29-2002, 01:53 AM
for some reason, the permissions of the target needed to be group:write to echo to a root:wheel owned file. i don't understand that.


% sudo chmod g=r foo

% ll foo
-rw-r----- 1 root wheel 4 Jan 28 22:47 foo

% sudo echo "foo" > foo
foo: Permission denied.

% sudo chmod g=rw foo

% ll foo
-rw-rw---- 1 root wheel 4 Jan 28 22:50 foo

% sudo echo "foo" > foo

% cat foo
foo


wonky cat food.

mervTormel
01-29-2002, 02:10 AM
your

~/Library/init/tcsh/environment.mine

is probably a clone of

/usr/share/init/tcsh/environment

and it is calling itself, and the shell runs out of file descriptors (spits up blood)

you should delete ~/Library/init/tcsh/environment.mine

if you do clone the default scripts to make .mine scripts, put an exit tatement after your customizations to prevent it from falling into the default code. right?

e.g.,

% cat Library/init/tcsh/environment.mine
##
# TCSH Expanded C-Shell INITIALIZATION FILE
# Global environment setup
<snip>

setenv PAGER less

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

bindkey -k down history-search-forward
bindkey -k up history-search-backward
bindkey -b ^H backward-delete-word

exit

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

lancelot183
01-29-2002, 02:27 AM
woohah! it works now.

valuable lessons have been learned here, thanks to you. :)

i had just copied all the files in /usr/share/init/tcsh straight to ~/Library/init/tcsh, not even thinking about the fact that if they try and do the same thing, then it starts doing nasty things...

i still am not entirely sure what happened originally. one theory, is that a package installed it's own csh.cshrc (for whatever reason), and then when i deinstalled it, it jsut deleted it altogether.
argh... that's one of the reasons i'm using a mac in the first place... so that kinda thing doesn't happen! oh well. i'll know better next time.

thanks again for your time!

if you're bored, take a look at my post about port forwarding... that's a whole 'nother ballgame i want to learn about.

sao
01-29-2002, 06:11 AM
mervTormel and Lancelot 183.

Learned a lot here. Thanks.

Cheers...

stetner
01-29-2002, 08:51 AM
Originally posted by mervTormel
for some reason, the permissions of the target needed to be group:write to echo to a root:wheel owned file. i don't understand that.

% sudo echo "foo" > foo
[/CODE]

wonky cat food.

Hey mT, I think you will find with the perms set group write you cat write to it like:

% echo "foo" > foo

By changing the file to be group writeable, you (who are in group wheel as an admin, see netinfo...) can write to it anyway.....

The problem when it does not work is that the redirection of output is happening as yourself (who when it is not group writeable can't write to it. Your command is saying take the output of the 'sudo' and put it into the file, but since you haven't sudo'ed yet, you can't.

Clear as mud??

Doug

mervTormel
01-29-2002, 10:44 AM
doug,

thanks. still a little murky...

is this a shell oddity?

what command would allow the authenticated subprocess to echo to a protected file, e.g.,

% ll /etc/csh.cshrc
-rw-r--r-- 1 root wheel 31 Sep 2 20:35 /etc/csh.cshrc

pmccann
01-30-2002, 02:17 AM
Hi again,

yep, this one's a bit of a pain: looks like you have to open a shell *as root*, because it's the shell that's doing the redirection.

One way to do what you're attempting is

sudo sh -c 'echo "me" > rootprotectedfile'

Interestingly (well, a little bit!): I don't see the "-c" option in the sh man page, but it is visible in the zshoptions page. It just says to "do the single command entered after this and exit" if I'm reading things correctly. Yep, that makes a lot of sense, and it *does* work for the sh shell even if it's not advertised widely!:

sh -c 'ls'

just prints out the directory contents and boots me back to my tcsh prompt. Anyway, the above is an ugly but effective means to do what you're after. I don't know any other way to achieve the same thing short of generating a root shell first and then having to exit.

Cheers,
Paul

mervTormel
01-30-2002, 02:52 AM
ppmmccaann,

thanks for diggin'

what i'm reading here is that shell csh (mother of tcsh) makes these kinds of things oblique, and that sh (mother of bash) have more better methods and can make these suck less.

i have it as a todo to figger this out and will post what i learn.

re:
--
sh -c 'ls'

just prints out the directory contents and boots me back to my tcsh prompt. Anyway, the above is an ugly but effective means to do what you're after. I don't know any other way to achieve the same thing short of generating a root shell first and then having to exit.
--

remember, every command you enter at the shell command line forks and execs a subprocess, and then the subprocess dies (true for this example). note the pid's:

shell=tcsh


% ps -a | grep ps
23866 std R+ 0:00.01 ps -a

# pid 23866 is now dead and stinkin'

% ps -a | grep ps
23868 std R+ 0:00.01 ps -a


'fork and exec', the new restaurant i would open if i had halfa brain.

regards,

-mt

pmccann
01-30-2002, 10:35 AM
Hi again,

sorry, I seem to have muddied the waters by using "sh" in the above: in fact (t)csh works in exactly the same way, in that both:

csh -c 'ls'

tcsh -c 'ls'

execute the single command in the new shell and then that shell exits. The exiting (and returning to your shell) is what I was commenting on there: 'cos if you just enter

csh (or tcsh)

(or sh of course) you spawn a new shell that lives until you knife it with an "exit". So "-c" means "spawn the shell, execute a single command within that new shell, and then exit, returning control to the original shell". Does that make more sense? [[For what it's worth there are a heap of "shell built-in" commands that should be able to run without having to generate a new process: cd, chdir, alias, echo and so on. Only time they force a new process is if they're in the middle of a pipeline, when a new shell is spawned to run them.]]

Anyway, for a real touch of funkiness I recommend trying to interpret the output from:

csh -c 'ps'
tcsh -c 'ps'

Oh yeah, I like the idea of "fork and exec". Let us know when it's open!

Cheers,
Paul