LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-14-2014, 11:08 AM   #1
rjkfsm
Member
 
Registered: Apr 2004
Location: Charleston, SC
Distribution: Debian, Gentoo, Knoppix & DSL
Posts: 122

Rep: Reputation: 15
Question SSH is changing environment variables


OK - I've been playing with *nix for a while, but I ran into this issue and it's probably something really obvious. I'm just not seeing it.

If I ssh into a box and type in a command (it doesn't matter) at the prompt, I get my expected results. If I send the command directly via ssh, I get different results.

I figured out the the environment variables change depending on how I do the command. For example, if I log into my box via ssh and I type in "set", I get all my environment variables and they are correct. If I log back out, and type in, "ssh $SERVER 'set'", I get a completely different set of variables.

What's going on here?

RK
 
Old 11-14-2014, 11:52 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
It may be caused by the differences in the interactive (first) vs non-interactive (second) shell.
 
Old 11-14-2014, 03:28 PM   #3
rjkfsm
Member
 
Registered: Apr 2004
Location: Charleston, SC
Distribution: Debian, Gentoo, Knoppix & DSL
Posts: 122

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by suicidaleggroll View Post
It may be caused by the differences in the interactive (first) vs non-interactive (second) shell.
I understand that, but why are they different?

RK
 
Old 11-14-2014, 03:40 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
An interactive vs non-interactive environment is different. Some variables might be set differently or not at all, it depends on the system. For example, if you run
Code:
ssh server
echo $PS1
versus
Code:
ssh server 'echo $PS1'
You will most likely get different results, chances are the second one will be blank. That's because a non-interactive session has no use for the environment variable that sets the command prompt format, so it doesn't bother to set it.

Without knowing how your results differ, that's as much as I can help. If you want more detail, you'll need to provide some yourself (eg: example output).
 
Old 11-15-2014, 04:47 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by rjkfsm View Post
I understand that, but why are they different?

RK
Part of the reason is that the environment IS different.

An interactive session has a terminal associated with it - and that allows things like PS1/PS2 to make sense. It also means that terminal types make sense (TERM environment variable). It also allows the bashrc, /ect/bashrc, or profile files to send data to the terminal (escape sequences) that set color, font selections...

In other cases it is the choice of the administrator.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Does changing environment variables always reflect on the shell? ulkoma Linux - Newbie 6 05-24-2013 08:59 AM
[SOLVED] using ssh cant access applications off of host, problem with environment variables josip76 Programming 15 10-22-2010 01:31 AM
changing environment variables. Geminias Linux - Newbie 2 01-04-2006 07:02 PM
SSH Displaying Environment Variables movitto Linux - Networking 5 08-12-2005 11:51 AM
retaining environment variables using ssh lightningdan Linux - Software 3 12-15-2004 06:43 PM


All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration