linux环境中,
A=1这种命名方式,变量作用域为当前线程
export命令出的变量作用域是当前进程及其子进程。
可以通过source 脚本,将脚本里面的变量放在当前进程中
附带自己写的tomcat启动脚本
#!/bin/bashcat <startupTomcat.shck=\`ps -ef | grep tomcat1 | grep java | wc -l\`if [ \$ck = 0 ]; then /home/wdj/tomcat1/bin/startup.shexit 1fiEOF#ֱ直接执行该命令是不行的,因为tomcat启动需要JAVA_HOME变量,A=1这种方式,变量作用域为当前线程,export命令出的变量作用域是当前进程及其子进程。source 脚本,将里面的变量放在当前进程中cat < shutdownTomcat.shck=\`ps -ef | grep tomcat1 | grep java | wc -l\`if [ \$ck = 1 ]; then /home/wdj/tomcat1/bin/shutdown.shexit 1fiEOFif [ "$1" = "0" ] then SHELL=shutdownTomcat.shelif [ "$1" = "1" ] then SHELL=startupTomcat.shelse echo "you must input param 0 or 1" exit 1fiSERVERS="192.168.10.150 192.168.10.151"for SERVER in $SERVERSdo /usr/bin/expect <<-EOF set timeout -1 spawn scp $SHELL $SERVER:/ expect { spawn scp $SHELL $SERVER:/ expect { "*yes/no*" {send "yes\r"} "*password*" {send "1234567\r"} } spawn ssh $SERVER "source /etc/profile;chmod +x /$SHELL;/$SHELL;rm -rf /$SHELL" expect { "*yes/no*" {send "yes\r"} "*password*" {send "1234567\r"} } sleep 1 EOFdone