2017-09-13 97 views
0

我有一个shell脚本执行到远程shell的问题。获取远程shell变量的问题

我无法获得$ ARQ_END的价值。

ssh -T [email protected] << 'EOSSH' 

/app/work/leo/ReturnFileName.sh #This script returns a filename like: ADDRESS_BR_RECIFE_20170913.txt 
ARQ_END="`/app/work/leo/ReturnFileName.sh`" 
EOSSH 

echo $ARQ_END #Returns nothing! Expected to return: ADDRESS_BR_RECIFE_20170913.txt 

回答

1

在子shell中设置变量在父shell中不可见。你需要直接在父shell中设置变量。做到这一点的方法是将ReturnFileName.sh的输出通过ssh会话传递给父shell,并将其捕获到那里。

ARQ_END=$(ssh [email protected] /app/work/leo/ReturnFileName.sh) 
echo "$ARQ_END" 
0

谢谢,它的工作原理! 我使用了你发布的案例:

ARQ_END=$(ssh [email protected] /app/work/leo/ReturnFileName.sh) 
echo "$ARQ_END"