在命令行中:
1、su user -c "shell命令"。-c 后面跟shell命令
如su root -c "cd ~; touch 1.txt"
2、su user -s /bin/bash xxx.sh。-s 后面跟一個shell腳本
如 su root -s /bin/bash ./test.sh
test.sh內容如下:
#! /bin/bash
cd ~;
touch 1.txt;
mkdir tmp;
3、su user << EOF
xxx
xxx
EOF
如
在shell腳本中執行:
1、
2、
3、