Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just updated Cygwin and the new .bashrc contains this line right at the top:

# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return

I understand if not running interactive, you don't need to do anything, but my problem is that if I ssh with a command:

ssh localhost pwd

I see this:


So, obviously, it fails the [[ "$-" != *i* ]] test and returns. Obviously ssh localhost pwd is a trivial example, but I expect .bashrc to be run all the way through if running a command through ssh. My actual automation runs commands remotely against this cygwin instance and is failing because the path (which is set by my .bashrc) is not getting set correctly.

Furthermore, can anyone explain what that test is actually doing? What is i? What is $- supposed to represent?

share|improve this question

If you run a single command (pwd in your case) through ssh, it is not an interactive shell, so the behavior is correct, in my opinion.

You should set your PATH in ~/.profile or ~/.bash_profile, not in ~/.bashrc.

As found in bash(1) man page:

      Special Parameters
          The shell treats several parameters specially.   These  parameters  may
          only be referenced; assignment to them is not allowed.
          -      Expands  to  the  current option flags as specified upon invoca-
                 tion, by the set builtin command, or  those  set  by  the  shell
                 itself (such as the -i option).

So i contained in $- means that the -i option has been used (or automatically set by the shell, being interactive).

share|improve this answer

Your Answer


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.