0

I'm confused. I want find JAVA_HOME value in server and type this code in bash script.

ssh username@server "echo ${JAVA_HOME}"

and try

ssh username@server "echo $JAVA_HOME"

or

 ssh username@server 'echo $JAVA_HOME'

and all of they not worked;

I replace "JAVA_HOME" with "PATH" and it's work; I connect with ssh to server and try "echo $JAVA_HOME " and it's work. I think the problem is "_" and I don't know how fix it. please help me

icktoofay
  • 126,289
  • 21
  • 250
  • 231
vahid
  • 446
  • 6
  • 21
  • 2
    I don't think that the problem is `_` but rather that `JAVA_HOME` is not set in the environment you SSH into (hint: interactive shell vs. non-interactive shell). Use `set` to see *all* defined environment variables. – Joachim Sauer Nov 07 '12 at 08:57
  • I used "set" and JAVA_HOME is defined. – vahid Nov 07 '12 at 09:07
  • did you call `set` from an interactive shell or exactly as you'd called `echo` (i.e. `ssh username@server 'set'`)? – Joachim Sauer Nov 07 '12 at 09:11
  • In interactive JAVA_HOME is defined but in non-interactive is not defined. – vahid Nov 07 '12 at 09:20
  • well, then there's your problem. You need to check the appropriate initialization files of your shell to see where it's defined and where it *should* be defined. – Joachim Sauer Nov 07 '12 at 09:20

1 Answers1

1

Your approach is not feasible.

$JAVA_HOME will be interpreted to the variable value in localhost instead of the remote server. Besides, executing by ssh is not a login shell, you will not get environment variables defined in /etc/profile
William Bao
  • 298
  • 3
  • 6