如何在shell脚本中切换用户后一次执行多条命令


在命令行中:

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、

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM