系统:centos 6.x脚本内容:cat t.sh
复制代码代码如下:
#!/bin/bash su - test <<EOF pwd; exit; EOF
执行结果图:
当然也可以用下面的命令来执行
su - test -c "pwd"
ps: 切换用户只执行一条命令的可以用: su - oracle -c command 切换用户执行一个shell文件可以用:su - oracle -s /bin/bash shell.sh