求教:$sudo su -c 'll' other_user ... error: command not found
- 0次
- 2021-07-15 13:54:41
- idczone
我想在当前用户下,切换到另外一个用户,并且执行一些命令。
这些命令有.bashrc 或者 .profile里面定义的alias
如何可以不用通过切换用户,直接用类似于su -c,搞出?
gracis
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/>alias sudo='sudo '
不是很明白
这个命令中的sudo,可以不用
直接```su - -c 'll' other_user```
或者```su -c 'll' other_user```
也是一个意思,但是都不成功
试试,给你要执行的用户的bashrc里加上alais ll='ls -l'
在other_user的bashrc里面已经有这个alias了。。。
不太明白楼主的意思。
不知道这种方式会不会导入另一个用户自己的.bashrc:
sudo -u 用户名 bash -c "命令"
或者试试这种方式:
echo "source ~/.bashrc ; source ~/.profile ; 你要执行的命令" | sudo -u 用户名 bash -