Whenever I try to use the variable declared inside my SSH session it gives me blank output. Here is the code which I am trying to execute:

ssh -T host <<\HERE
export usage1=$(df -h |grep /nas/infa|sed s/%//g| awk '{printf("%d\n",$4)}');
echo $usage1
echo $usage1

I am able to get the desired output inside the SSH session, but when calling the same variable outside the SSH it gives me blank.


To get the value from the remotely executed command into a variable in your local environment, it's the same as getting the value of a locally executed command into your local environment, e.g.,

export usage1=$(ssh -T host <<\HERE
df -h|grep /nas/infa|sed s/%//g|awk '{printf("%d\n",$4)}'
echo $usage1
| improve this answer | |
  • Thanks,It solves the current situation, but isn't there anyway to use the variable declared inside the ssh environment locally? – Aishwarya Jhawar Sep 24 '16 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.