delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/11/12/08:06:51

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
From: "Brian Wilson" <wilson AT ds DOT net>
To: cygwin AT cygwin DOT com
Subject: Re: environment variables in ssh non-interactive shell
Date: Mon, 12 Nov 2012 08:06:26 -0500
Message-Id: <20121112124603.M62035@ds.net>
In-Reply-To: <CALvQJKtk12V1E1s68_4WvmAaswPk+=iaB=h3+Yupfz=TKAb9Fg@mail.gmail.com>
References: <CALvQJKtk12V1E1s68_4WvmAaswPk+=iaB=h3+Yupfz=TKAb9Fg AT mail DOT gmail DOT com>
X-OriginatingIP: 65.12.174.114 (wilson)
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

> I'm trying to use environment variables to pilot a windows system
> through cygwin+ssh. Things work nicely with an interactive shell, but
> mess up with a non-interactive shell because my environment variables
> aren't set.
<< -snip- >>
> Does anyone have an idea what could be wrong?

I'd suggest a simple approach like testing to see if there is a terminal 
attached then source in the .bashrc or other environment setting files.  Try 
something like this:

[[ ! -t 1 ]] && [[ -f ~/.bashrc ]] && . ~/.bashrc

If there is no terminal attached to the session, and there is a .bashrc file 
in ${HOME}, source the file into the current environment.  You may want to do 
something similar for the /etc/profile or ~/.profile files in which case I 
would use a regular "if" styled statement.  Make sure ${HOME} is set 
(obviously) or explicitly set the value if it is not set in the script.  
Carefully check the file permissions to make sure everything has the correct 
read, write, and execute permissions (i.e. You don't want to execute a file 
that just anyone can write into) or you may get a nasty surprise.

if [[ ! -t 1 ]]
then
     echo -e "\n\tNo interactive terminal found for this session.\n\tSetting 
the environment.\n"
     [[ "${HOME}" = "" ]] && HOME=/usr/<usr_dir>/...
     if [[ -f /etc/profile ]]
     then
          . /etc/profile
     fi
     if [[ -f ${HOME}/.profile ]]
     then
          . ${HOME}/.profile
     fi
     if [[ -f ${HOME}/.bashrc ]]
     then
          . ${HOME}/.bashrc
     fi
fi


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019