0

Using Linux and bash:

in remote .bashrc file I've export FOO="hello"

locally I run this command but none variable was showed

ssh user1@192.168.1.114 ". /home/user1/.bashrc && echo \$FOO"

How could I get remote FOO variable?

np_6
  • 514
  • 1
  • 6
  • 19
gekomad
  • 525
  • 9
  • 17
  • If you want to track what's happening, add a `set -x` to your command. That is: `ssh user1@192.168.1.114 $'PS4=\'${BASH_SOURCE}:${LINENO}+\'; set -x; . /home/user1/.bashrc && echo "$FOO"'`. Right now, there isn't enough information in this question for it to be answerable -- editing in the trace transcript `set -x` creates will help. – Charles Duffy Apr 25 '21 at 17:09
  • Does this answer your question? [ssh command execution doesn't consider .bashrc | .bash_login | .ssh/rc?](https://stackoverflow.com/questions/1198378/ssh-command-execution-doesnt-consider-bashrc-bash-login-ssh-rc) – 0stone0 Apr 25 '21 at 17:12
  • 3
    @0stone0, the OP is _explicitly_ sourcing the remote `.bashrc`, so that makes it distinct from the questions about why that isn't happening automatically. And I don't see them trying to use local variables (and they're escaping their expansion to prevent local evaluation), so I don't think the first proposed duplicate is a match either. That said, I also don't think this is answerable; it shows us what they're doing right, but doesn't give us enough information to know what it is they're doing wrong. – Charles Duffy Apr 25 '21 at 17:12
  • Try this `ssh user1@192.168.1.114 '. /home/user1/.bashrc ; echo $FOO'` – Philippe Apr 25 '21 at 20:14
  • Your command to print `FOO` is wrong. It's either `printenv ECHO` or `echo $FOO` to show the value of an exported variable. – user1934428 Apr 26 '21 at 07:27
  • @gekomad : Your question is a bit unclear to me. You are talking about a remote server, but the code you posted does not show any remote access. – user1934428 Apr 26 '21 at 07:28

1 Answers1

1

I suggest with bash:

source <(ssh user1@192.168.1.114 cat /home/user1/.bashrc)
declare -p FOO

Output:

declare -x FOO="hello"

I assume /home/user1/.bashrc contains export FOO="hello".

Cyrus
  • 84,225
  • 14
  • 89
  • 153