views:

85

answers:

2

I just started using a Solaris 10 (Sparc) box where I telnet in and get confronted with a very unfriendly interface (compared to the standard bash shell I use in cygwin or linux) --- the arrow keys do not work as I expect them to. Being an NIS system, changing the shell is not as easy as using the "chsh" command. And setting the SHELL environment variable in ~/.login and ~/.profile is not working for me. So I'm thinking that I may need to write a script to determine if bash is running the script and starting bash if the answer is no. My first attempt, trying to invoke /bin/bash from ~/.profile seems to work but kind of doesn't feel right. Other suggestions? And how do I tell programmatically which shell is actually executing?

A: 

You can tell what shell is running with echo $0. For example:

$ echo $0   
-bash

If you're changing shell you probably want to replace the current shell process rather than be a child of it, so use exec.

Also, you want to pass bash the -l flag so it acts as if it has been called as part of the login process.

So you'll want something like:

exec bash -l
Dave Webb
+1 on "exec bash -l" but how to I prevent the recursion? Here's what I wrote:...if [ "$0" != "-bash" ] ; then echo Starting bash... exec bash -lfiand when I run this it continues to spawn new bash processes. :-(
pajato0
Sorry for the squished script shown in the previous comment. The actual code is correctly formatted.
pajato0
If seems $0 returns "bash" if it's not a log in shell so try: if [ "$0" != "-bash" -a "$0" != "bash" ]; then
Dave Webb
Very nice. Thanks for the lesson.
pajato0
Instead of matching $0, which is not very reliable, you can check for a bash-specific variable: [ -z "$BASH_VERSION" ] || exec bash -l
Idelic
A: 

You are probably running with ksh(1) on Solaris. You have several options, read the manpage for ksh and configure it or install another shell you're more familiar with like bash. I'd personnaly recommend zsh.

Keltia
I like your advice about installing another shell I'm more familiar with. Bash would be good. How does one do that in a NIS environment?
pajato0
Look on your system for the ypchsh program (/usr/sbin or something close). Check /etc/shells for valid shells and use ypchsh to change your login shell to bash. If bash is not here, install (or ask your admin to do it).As a last resort you could compile and install bash in your $HOME/bin and use that "exec $HOME/bin/bash" in .profile...
Keltia