Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

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

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:

BEFORE TEST

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
add comment

1 Answer 1

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:

   PARAMETERS
      (...)
      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
add comment

Your Answer

 
discard

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.