我想在当前用户下,切换到另外一个用户,并且执行一些命令。
这些命令有.bashrc 或者 .profile里面定义的alias
如何可以不用通过切换用户,直接用类似于su -c,搞出?
gracis
这些命令有.bashrc 或者 .profile里面定义的alias
如何可以不用通过切换用户,直接用类似于su -c,搞出?
gracis
1
yangg Nov 7, 2014
# enable sudo with aliases
# If the last character of the alias value is a space or tab character, # then the next command word following the alias is also checked for alias expansion. # http://www.gnu.org/software/bash/manual/bashref.html#Aliases alias sudo='sudo ' |
2
calebx OP @yangg 不是很明白
这个命令中的sudo,可以不用 直接```su - -c 'll' other_user``` 或者```su -c 'll' other_user``` 也是一个意思,但是都不成功 |
3
yangg Nov 7, 2014
试试,给你要执行的用户的bashrc里加上alais ll='ls -l'
|
4
calebx OP 在other_user的bashrc里面已经有这个alias了。。。
|
5
extreme Nov 10, 2014
不太明白楼主的意思。
不知道这种方式会不会导入另一个用户自己的.bashrc: sudo -u 用户名 bash -c "命令" 或者试试这种方式: echo "source ~/.bashrc ; source ~/.profile ; 你要执行的命令" | sudo -u 用户名 bash - |