You are not logged in.
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
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
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
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