ksh and .profile

hi,

I have the following in my .profile file:

    21          set -u
    22          trap "echo 'logout'" 0
    23
    24
    25          EDITOR=vi
    26          export EDITOR
    27
    28          export ENV=x.tm

And x.tm just contains

echo hello world

I am in the c shell. I was under the impression that if I type ksh, then the .profile will get executed, and it will also execute x.tm. But I do not see hello world printed out.
In addition, if I manually do .profile, then I get

$ .profile
.profile[11]: setenv:  not found
logout

Can anyone explain why this is so?

Thanks.

On line 11 in your .profile file there is a setenv statement. That generates an error which forces the ksh shell to exit.

Doesn't work like that, if you default login is csh. At least it doesn't work for me:)

no, this is my line 11:

     8          then
     9                  eval ` tset -s -Q -m ':?hp' `
    10          else
    11                  eval ` tset -s -Q `
    12          fi

But I think the shell is somehow looking at line 11 of uncommented lines, which seems to be the set -u. In any case, there is NO setenv!

Thanks.

.profile is run automatically when you login with ksh as your login shell, not when you type ksh. You said that you were using csh. tset will notice that and output setenv statements for you. The backticks try to run the output from tset.

thanks for the reply, but I am still a little confused.

ok, so .profile is not executed when I type ksh and go to the korn shell. But I would have thought that if I then did .profile in the korn shell, it will at least run that script (which looks like below)

       if [ "$TERM" = "" ]
        then
                eval ` tset -s -Q -m ':?hp' `
        else
                eval ` tset -s -Q `
        fi
        stty erase "^H" kill "^U" intr "^C" eof "^D"
        tabs

        PATH=$PATH:.

        set -u
        trap "echo 'logout'" 0

        EDITOR=vi
        export EDITOR

        export ENV=x.tm

However, I get:

$  . ./.profile
ksh: setenv:  not found

I just don't know where this setenv is coming from. It is not in my script!

thanks

Notice that I said "tset will notice that and output setenv statements for you. The backticks try to run the output from tset." That is what is happening. What effect did expect from
eval ` tset -s -Q `

$
$
$ cat script1
#! /usr/bin/ksh
echo setenv this that
exit 0
$
$
$ cat script2
#! /usr/bin/ksh
eval `./script1`
exit 0
$
$
$
$ ./script1
setenv this that
$ ./script2
./script2: setenv: not found
$

script2 has no setenv statement either. But it is trying to run one.

thanks. I'll have to read up on tset to understand exactly what it is doing.

I was reading another thread of yours

and I have three questions

first, my system is set up so that when I login the csh is invoked. Now to get to my korn shell, I type ksh. But I cannot do su - username, as that always takes me to another csh. All my korn shell settings are in .profile. Is there another way for me to call korn shell preceded with - so that my .profile gets executed? (without me having to source it manually).

when I source my .profile manually, the ENV file seems to lose the speacial meaning as it does not seem to be called. Is this expected?

in the above thread you talk about ps -pf $$. I am assuming $$ means the pid of the running shell, yes?

thanks for your help.

Well, $$ is the pid of the current process. No, the ENV should not be affected by sourcing a file unless you fiddle with the ENV file. And you should not be trying to mislead a subshell into thinking it is a login shell.

The best thing for you to do would be to switch your shell to ksh and csh and just use a single interactive shell. If you don't want to do that, then your login script (.login or .profile) should set up your environment and only your environment without touching anything else. Your environment is the stuff that gets printed wit the commands "printenv" and "env". Your one unified environment must be powerful enough for any interactive shell. That means, for example, that your csh .login must establish the ENV variable for later use with ksh. Each shell that you use must have a startup script. That script will check to see if the shell is interactive. If so, it will do any aliases, options, etc that you need for interactive work.

It will take some effort to get all of this working for unix was not designed to support multiple interactive shells. Everyone else picks one... at least for a while. There is a chsh command on many versions of unix so you can switch later.

wow, we have chsh on our system and it worked. Great!

I also like the ps -pf $$ a lot better than using $SHELL, as $SHELL can be changed by someone. I was surprised a book mentioned that $SHELL should be used to find out your shell and not the other way!

thanks