linux shell 切换用户并执行命令

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 "要执行的命令" 

即可

猜你喜欢

转载自blog.csdn.net/Arvinzr/article/details/79916608