You are not logged in.

#1 2009-05-07 19:29:17

beretta
Member
Registered: 2008-04-21
Posts: 133

::SOLVED:: change bash prompt while in ssh

I'm learning how to use bash bit by bit, but came up with a question I'm not certain how to solve.  I learned some time ago about setting the PS1 variable to customize the shell prompt, and have a nice prompt I like using.  However, it would be nice to have the prompt be flagged if I'm logged in through ssh as opposed to directly on the computer itself.  How could I do this?

One thought I had was to check to see if certain environment variables exist (eg. $SSH_CONNECTION).
Doing if [ $SSH_CONNECTION ]; then ... fi gives an error about too many arguments.  None of the other SSH related variables seem to be just a number value.  Is there a way to test for the existence of a variable in bash?

Last edited by beretta (2009-05-07 20:44:06)

Offline

#2 2009-05-07 19:36:40

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: ::SOLVED:: change bash prompt while in ssh

What you want is [ -n "$SSH_CONNECTION" ] (variable is set/nonzero length) or the opposite [ -z "$SSH_CONNECTION" ] (variable is not set/zero length)

Offline

#3 2009-05-07 20:18:03

Neb
Member
Registered: 2009-04-29
Posts: 13

Re: ::SOLVED:: change bash prompt while in ssh

You can just type to variable you want to see

Shows current PS1 Value

 $ echo $PS1

And after editing your ~/.bashrc just type the following to load it

$ source ~/.bashrc

Offline

#4 2009-05-07 20:43:43

beretta
Member
Registered: 2008-04-21
Posts: 133

Re: ::SOLVED:: change bash prompt while in ssh

Procyon wrote:

What you want is [ -n "$SSH_CONNECTION" ] (variable is set/nonzero length) or the opposite [ -z "$SSH_CONNECTION" ] (variable is not set/zero length)

Thanks-- that got it.  I was missing the quotes, so it was expanding at the spaces rather than interpreting the entire thing as a string.

Offline

Board footer

Powered by FluxBB