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 want to be able to set a custom prompt (to help with automating jobs, the prompt should be something I can reliably detect). I found I am able to set the prompt remotely, like this:

wim@wim-acer:~$ ssh guest@192.168.1.124 -i ~/.ssh/guest_nopassphrase 
~ # echo $PS1
\w \$
~ # PS1='Setting a custom prompt \w \$ '
Setting a custom prompt ~ # exit
Connection to 192.168.1.124 closed.

Is there a way to do it in one shot in the first place, by using a different ssh command? The suggestion I tried in the answer of a related question didn't work for me:

wim@wim-acer:~$ ssh guest@192.168.1.124 -i ~/.ssh/guest_nopassphrase -t "PS1='Sending a custom prompt \w \$ '; exec sh"
~ # set
HOME='/var/tmp'
IFS='   
'
LOGNAME='guest'
PATH='/sbin:/usr/sbin:/bin:/usr/bin'
PPID='1039'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD=''
SHELL='/bin/sh'
TERM='xterm'
USER='guest'
share|improve this question
    
Not even if you add export just in front of PS1=? –  Eroen Mar 13 '12 at 5:56
    
ah, your suggestion worked :) if you add it as an answer, i can accept it tomorrow. –  wim Mar 13 '12 at 6:03
    
I just have it changed in my .bashrc file so I know what I'm on at a glance by what info is shown. –  Rob Mar 13 '12 at 6:18
    
@Rob do you mean the .bashrc file on the remote machine? if so, that is not an option for me –  wim Mar 13 '12 at 6:36

2 Answers 2

up vote 3 down vote accepted
$ ssh ::1 -t "export PS1='Sending a custom prompt \w \$ '; exec sh"
Password: 
Sending a custom prompt ~ $ exit
Connection to ::1 closed.
share|improve this answer

Did you consider editing the .bashrc file on the remote host?

A simple:

export PS1='Setting a custom prompt \w \$ '

at the end of ~/.bashrc on the remote host will make sure the prompt is changed each time you log in. It will obviously affect any other users of the account too.

share|improve this answer
    
Thanks, I considered it - but I need to do it on hundreds of dumb boxes, so it is preferably to be able to send it on the fly rather than set it up on each one. –  wim Mar 13 '12 at 6:48

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.