pull via ssh

Sami Tikka sontikka at welho.com
Sun Aug 7 17:08:02 CDT 2005


4.8.2005 kello 13:32, Thomas Arendsen Hein kirjoitti:

> To check if printing is save in the login scripts, you can use the
> 'tty' command:
>
> tty > /dev/null && echo "Welcome"
>
> or:
>
> if tty > /dev/null; then
>     echo "Welcome"
>     echo "some more text"
> fi
>

Traditionally one has checked if the shell is an interactive one before 
printing out such nonsense or changing tty-related settings. Every 
shell has a way to figure out if it is running interactive or not. A 
quote from the bash man page:

        An interactive shell is one started without  non-option  
arguments  and
        without  the  -c  option  whose standard input and output are 
both con-
        nected to terminals (as determined by isatty(3)), or one  
started  with
        the  -i  option.   PS1 is set and $- includes i if bash is 
interactive,
        allowing a shell script or a startup file to test this state.

So you could check it with something like:

case $i in
*i*) echo "Welcome";;
esac

Many times the initialization files read by the shell are different 
depending on if the shell is interactive or not. E.g. with bash all 
that is needed is to put the extra outputs in .bash_profile

-- Sami



More information about the Mercurial mailing list