Console/SSH/X: How to tell?

Marc Lanctot lanctot-yfeSBMgouQgsA/PxXw9srA at public.gmane.org
Fri Jun 19 20:34:06 UTC 2009


On Fri, 19 Jun 2009 13:17:29 -0700
Ian Petersen <ispeters-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:

> On Fri, Jun 19, 2009 at 12:36 PM, Marc Lanctot<lanctot-yfeSBMgouQgsA/PxXw9srA at public.gmane.org>
> wrote:
> > Can I do this? If so, how?
> 
> There are several start-up scripts that Bash typically sources, I
> think.  One of them is for interactive shells, the other not.  You
> just need to find the right file to put your change into and I'm
> guessing .bashrc is the wrong one.  Someone more knowledgeable than me
> could tell you the name of the file for sure, but it might be
> .bash_profile.  You might find it yourself in man bash, but that's a
> lot of reading.

Yeah, that's what I expected. Turns out it wasn't so bad in the end ;) 

Here's the solution. $- contains 'i' if the shell is interactive (which
it's not when invoked through scp or ssh), so this does it:

INTERACTIVE=`echo $- | grep i`
if [ -n "$INTERACTIVE" ]
then
  # interactive-only commands
fi

Marc

-- 
Any code of your own that you haven't looked at for six or more months
might as well have been written by someone else.
  -- Eagleson's law
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list