ksh to bash mode

Hi guys...
I have a ksh shell by default, so when I login to my unix box, all my .profile statements gets executed(including the aliases).
But for some reasons(may be not comfortable using ksh), I would always switch to BASH(in the same session but as a child process) but in the process I am loosing all the aliases which were active in my parent (ksh)...
I understand that by typing BASH at the cmd line, I am starting a child process which should atleast inherit the charateristics(aliases etc) of the immediate parent....But in this case, its not happening.
Can somebody explain me this scenario?...and If there is a best(minimal) way to have the similar behavior as the parent, what would that be?...

PS: Please don't advice to DOT the profile once again !

-Anduzzi

And why don't you just change your login shell?

If you cannot change your login shell add the following in your .profile:

[ -x /path/to/bash ]&&exec /path/to/bash -l

Thanks for the input.
Could you please eloberate on this command?..I need to know what exactly I
[ -x /path/to/bash ]&&exec /path/to/bash -l
am doing here...

-Anduzzi

-x checks if you have permission to execute the file (the bash shell in this case), if the test returns true, substitutes (the exec builtin) your current shell with bash run as a login shell (the -l switch).

Thx...
Does this substitution pre-vail multiple sessions?....or
when I log out of the current session, the login shell will be back to KSH again?..which means I am dealing with a single session ONLY with out effecting other developers !!!

-Anduzzi

If you put that command in .profile it will affect everyone using that initialization file (the same username). If you put that in .kshrc or whatever file you use for your interactive sessions, it will affect all interactive sessions that use that rc file.

Alright...I see your suggestion here...
But, I don't have any .kshrc(or any kind of such interactive programs) in my HOME which forces me to change the .profile.

Am I missing something?..

-Anduzzi

You could create it. What version of ksh you are using? On what platform?

Sorry,
anyone having the same home directory or some custom way to pass an initialization file to the shell.

dude...thx for your instant answers...appreciate that...
My KSH version : ksh88
My OS: SUN Solaris

Let me know what it takes to create a .kshrc file.
Do I need to have any admin privilges for doing this?.

-Anduzzi

No,
just run this command:

printf "%s\n" "[ -x /bin/bash ]&&exec  /bin/bash -l">"$HOME"/.kshrc

Then, leave your current session open (just in case something goes wrong) and start a new one. Check your current shell in the new terminal:

ps -p $$

If it's bash, it should be OK.

Unfortunately, I dont have a bash dir under /bin.

xsdetl01:/bin: ls -lart | grep '^d'
drwxr-xr-x 2 root bin 512 Sep 8 2007 sparcv7
drwxr-xr-x 2 root bin 1024 Sep 8 2007 sparcv9

I ran ur command though....it wudnt give out any error...
but opening up a new terminal, the shell doesnt change....

-Anduzzi

So just type:

type bash

... and change the path accordingly.

Sorry....thats my bad....bash file exists in /usr/bin.
but when I execute your cmd, just the statement (AS IT IS) goes into .kshrc and there is no execution.
When I execute .kshrc alone with the command inside it, the session completely exits.

Can we debug this?..

-Anduzzi

Yep,
just tried this on an old Solaris machine and it works :slight_smile:

Create an empty .bash_profile.
The existence of this file will prevent the exec'd bash from trying to
read ~/.profile, and re-executing itself over and over again.

touch "$HOME"/.bash_profile
  1. Execute the following command:
printf "%s\n" '[ -x /usr/bin/bash -a "$PS1" ]&&exec  /usr/bin/bash --login'>>"$HOME"/.profile

Leave your current session open, start a new one (.profile is read only on logon, so if you open a new session from the same terminal, that won't work).

Cool...
but b4 executing this, I want to make sure that we are getting step 2 right..
Are you trying to throw the o/p of step 2 to .profile or .bash_profile?..

I dont want to touch the existing profile...right?...

-Anduzzi

You should modify the existing profile (note the >> append redirection).
I cannot get my old ksh88 to read .kshrc ...
That's why I added the test for interactive shell $PS1, to simulate the rc behavior.

You should:

  1. Create an empty(for now:)) .bash_profile.
  2. Modify your existing .profile (make a backup copy first).