Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to configure my PuTTY session in such a way that I could login to a remote host, and (a) start bash (b) change the PS1 variable (prompt content) (c) continue work in the session as normal.

I tried:

  1. Connection -> Data -> Environment variables [does not work; session looks as if (b) had not been executed] AND
  2. Connection -> SSH -> Remote command: PS1="some stuff" [the window with the session opens for a fraction of sec, and then it closes]

Any ideas? I had had a look to some similar questions in the forum, but did not find anything helpful.

More generally: I log in into a host where many users log in as a single user, and thus they all share the 'settings' of the single user. I look for a method of forcing PuTTY into changing some of these settings temporarily (i.e., such that they would be time limited to the session that I open using PuTTY). Sort of running personal version of .bashrc within the session. Hope this makes sense.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

The target server needs to be configured to accept setting environment variables for the 1st option to work. The second is actually working fine, the problem is that it is designed to mimic

ssh user@foo command

which will just connect, run command and exit. You can have it remain open by giving it command; bash but that won't work for setting your variables sice a new shell will be started after the variable has been set.

So, short of having root access to the server so that you can enable the setting of environmental variables, the only way I can think of for you to do this is to edit ~/.bashrc the server and define your PS1 there. Add this line to ~/.bashrc:

PS1="some stuff"

Now, every time you log into that server, the prompt will be set for you.


Another way to do this would be to use a different rcfile for your bash session. Create a new file with these lines:

source /etc/profile
source ~/.bashrc
PS1='some stuff'

Save it as, for example, ~/.myps1, then in your putty settings, set the command to run on the remote server to:

bash --rcfile ~/.myps1

This will open a new shell session o the remote server and read in the file above which first reads .bashrc and then sets PS1.

share|improve this answer
    
I added a note to the original question. Problem is that the .bashrc is shared among all the users who log in, and I cannot modify it... I could create a personalized .bashrc-my, but then I still don't know how could I call it when logging in with PuTTY. –  Simon Righley Jan 29 at 17:42
    
@SimonRighley OK, can you set the server to allow setting of env variables as described in the post I linked to? You could always just add an alias to the shared .bashrc: alias ps1="PS1='some stuff'" and then run the alias each time you log in. –  terdon Jan 29 at 17:54
    
@SimonRighley see updated answer for another solution. –  terdon Jan 29 at 18:04
    
Fantastic! That did the trick :) Thank you so much! Spent so much time trying to figure this out... Can I now define all sort of aliases, variables and what not in the ~/.myps1 (I called it ~/.bashrc-my_name), and the protocol you described will respect the settings from the default .bashrc, and after that (on top of it?) it will read in all that I'll define in bashrc-my_name? –  Simon Righley Jan 29 at 18:17
1  
@SimonRighley yup. As long as you source the global .bashrc first, anything you do after that will supersede any settings you have in .bashrc. Settings in .bashrc that are not overwritten by commands in .bashrc-my_name will persist. –  terdon Jan 29 at 18:18

Try setting the remote command to something like export PS1='foo'; /usr/bin/bash... that should spawn a bash session after setting PS1.

share|improve this answer
    
That won't because PS1 will be reset when the new shell is started since PS1 is normally set in one of the global config files. –  terdon Jan 29 at 17:58
    
It worked in my environment, but everyone's setup is potentially different. For reference I tested against HP-UX, which is admittedly not very common anymore. –  BowlesCR Jan 29 at 18:02
    
I report that, unfortunately, it does not help. The PS1 value is back to the default one. –  Simon Righley Jan 29 at 18:04
    
@BowlesCR it worked probably because your PS1 is not being set in any of the default rcfiles. In most cases, starting the new shell will overwrite the exported PS1 with whatever is in the default startup files. –  terdon Jan 29 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.