# Run on Interactive Login Only

## Kenji Miyamoto

I've run into a dilemma with Bash's login process.  On a certain server where I don't have administrative privileges, I've set it up so that whenever Bash starts, ZSH comes up.  Unfortunately, that breaks SCP and SFTP, which apparently require that sort of thing to not happen.

Is there a way to tell if the session is interactive on login, so I could only start ZSH then?  I've tried .bashrc, which is how I did it above.

----------

## RazielFMX

 *Kenji Miyamoto wrote:*   

> I've run into a dilemma with Bash's login process.  On a certain server where I don't have administrative privileges, I've set it up so that whenever Bash starts, ZSH comes up.  Unfortunately, that breaks SCP and SFTP, which apparently require that sort of thing to not happen.
> 
> Is there a way to tell if the session is interactive on login, so I could only start ZSH then?  I've tried .bashrc, which is how I did it above.

 

Yes actually, .bashrc is actually read when bash is simply invoked.  When a login shell is invoked, your .profile (for legacy systems, users moving from sh or ksh) and .bash_profile are read.  In your .bash_profile,  you should have something like this:

```

if [ -f ~/.bashrc ]; then

        source ~/.bashrc

fi

```

You should move the "exec zsh --login" from your .bashrc to your .bash_profile, and you should be good to go.

----------

## irasnyd

 *Kenji Miyamoto wrote:*   

> I've run into a dilemma with Bash's login process.  On a certain server where I don't have administrative privileges, I've set it up so that whenever Bash starts, ZSH comes up.  Unfortunately, that breaks SCP and SFTP, which apparently require that sort of thing to not happen.
> 
> Is there a way to tell if the session is interactive on login, so I could only start ZSH then?  I've tried .bashrc, which is how I did it above.

 

You may be able to run the "chsh" command, even if you don't have administrative priveleges. If this works, then just set your shell to zsh.

Other than that, I have the following in my .bashrc, right at the top:

```
# Test for an interactive shell.  There is no need to set anything

# past this point for scp and rcp, and it's important to refrain from

# outputting anything in those cases.

if [[ $- != *i* ]] ; then

        # Shell is non-interactive.  Be done now!

        return

fi

```

If you start zsh after that, scp and sftp should be fine, and you should get zsh on interactive logins, too.

----------

## Kenji Miyamoto

Unfortunately, chsh is only available for "installed" shells, whereas I compiled ZSH under my home directory.  chsh complains that it's not listed in the system-wide shells file.

If it's the case that .bashrc is only invoked with interactive login, why does having the line to execute ZSH prevent SCP file transfers from working?

----------

## RazielFMX

If you do what I said, your problem will be solved.  As a test, I added echo statements to the top of my .bashrc and .bash_profile files.  .bashrc IS NOT sourced by default on a login shell, which is why every .bash_profile you come across sources .bashrc, it is only sourced by non-interactive shells (like scp).

```

user@alexiea ~/tmp $ scp testsource.txt localhost:/home/user/tmp/testtarget.txt

.bashrc sourced

user@alexiea ~/tmp $

```

As you can see, .bashrc is sourced on SCP.  Thus, if you place your EXEC in your .bash_profile, it will only affect your login shell.

```

user@alexiea ~/tmp $ ssh localhost

Last login: Fri Mar 21 11:17:21 2008 from 192.168.1.101

.bash_profile sourced

.bashrc sourced

user@alexiea ~ $

```

As you can see, .bash_profile is sourced when you login, so you will get zsh.

EDIT:  Forgot to address this:

 *Kenji Miyamoto wrote:*   

> Unfortunately, chsh is only available for "installed" shells, whereas I compiled ZSH under my home directory.  chsh complains that it's not listed in the system-wide shells file.
> 
> If it's the case that .bashrc is only invoked with interactive login, why does having the line to execute ZSH prevent SCP file transfers from working?

 

Could be some sort of security protection built into the SSH protocol.  I had issues at work when I tried to exec bash in my .cshrc (my job only allows tcsh as a shell, I wanted bash  :Very Happy:  ).  I later placed in my .login (only read on login shell) and the issue was resolved.

----------

