Answers to: how to define variable in sshhttp://linuxexchange.org/questions/3525/how-to-define-variable-in-ssh<p>I need to use <code>ssh</code> to send command to different computers to run programs. Can I define a variable of <code>Directory</code> and <code>program</code> in front of this shell script? Then, I do not need to write them every time?</p> <p><code>host_list=("c15-0330-10.ad.mtu.edu" "c15-0330-11.ad.mtu.edu" "c15-0330-12.ad.mtu.edu")</code> <code># I have multiple programs</code> <code># program=c("L_1","L_2","L_3")</code> <code>ssh -f "${host_list[0]}" 'set Directory="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"; cd $Directory &amp;&amp; nohup Rscript L_1.R&gt; L_1_sh.txt;echo "The job L_1 is finished" |mutt "zwang10@mtu.edu" -s "The job L_1 is finished"'; ssh -f "${host_list[1]}" 'set Directory="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"; cd $Directory &amp;&amp; nohup Rscript L_2.R&gt; L_2_sh.txt;echo "The job L_2 is finished" |mutt "zwang10@mtu.edu" -s "The job L_2 is finished"'; ssh -f "${host_list[2]}" 'set Directory="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"; cd $Directory &amp;&amp; nohup Rscript L_3.R&gt; L_3_sh.txt;echo "The job L_3 is finished" |mutt "zwang10@mtu.edu" -s "The job L_3 is finished"';</code></p>enFri, 20 Jan 2017 11:47:56 -0000