sarmahdi
sarmahdi

Reputation: 1136

PS1='$PWD $ ' doesnt work from shell script

I am not a Solaris expert and I am trying to create a shell script that will change my prompt to PWD and the ksh to bash and I have this:

PS1='$PWD $ ' exec bash --noprofile --rcfile /dev/null

or

PS1='\w $' exec bash --noprofile --rcfile /dev/null

Both of them dont work from a sh. if i add them from the command line then the first time my bash appears on prompt and the second time the PS1='$PWD $' kicks in and my prompt changes.

Firstly, why is PS1='$PWD $' not working from shell script . and why do i have to run the command from command line twice to acheive my results.

Also, in my export/home/syed/ directory there are three files local.login, local.profile, and local.cshrc. is there any way i can use them that when ever i log in i dont need to run my shell script and upon login i get bash shell and my prompt as i want it (am i asking too much, i dont like the ksh as it does not have any features like up arrow recall last commands and tab auto complete features)

thanks Syed...

Upvotes: 1

Views: 1630

Answers (3)

Dennis Williamson
Dennis Williamson

Reputation: 360345

When you exec from within a script, the script is what is replaced, not the parent shell.

Try sourcing the script rather than running it.

Also, in Solaris, you can use passwd -e to change your login shell.

You may be able to symlink ~/.profile to your existing ~/local.profile (or similar). Note that .cshrc is for the C Shell and is not compatible with ksh or Bash.

Upvotes: 1

tripleee
tripleee

Reputation: 189679

When you exec bash it sets up its own environment from scratch. Pass it an --rcfile containing the settings you would like for it to inherit.

Upvotes: 0

Eran Ben-Natan
Eran Ben-Natan

Reputation: 2615

If you want that your default shell will be bash, change it in /etc/passwd

Upvotes: 1

Related Questions