su - elastic -c "echo export JAVA_HOME=/home/auto_deploy/jdk1.8 >> ~/.bash_profile " ; su - elastic -c "echo export CLASSPATH=$JAVA_HOME/lib" >> ~/.bash_profile ; su - elastic -c "echo export PATH=$PATH:$JAVA_HOME/bin >> ~/.bash_profile "; su - elastic -c "source ~/.bash_profile " ; 有时候会用到在当前用户下切换用户,并执行命令,然后再回到当前用户这种情况
su - elastic -c "source ~/.bash_profile " ;
su - elastic -c "source ~/.bash_profile "
su - 【用户名】 -c "要执行的命令"
即可