V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
calebx
V2EX  ›  Linux

求教:$sudo su -c 'll' other_user ... error: command not found

  •  1
     
  •   calebx · 2014-11-07 13:49:50 +08:00 · 2649 次点击
    这是一个创建于 3456 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想在当前用户下,切换到另外一个用户,并且执行一些命令。
    这些命令有.bashrc 或者 .profile里面定义的alias

    如何可以不用通过切换用户,直接用类似于su -c,搞出?
    gracis
    5 条回复    2014-11-10 13:25:39 +08:00
    yangg
        1
    yangg  
       2014-11-07 13:58:52 +08:00
    # 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 '
    calebx
        2
    calebx  
    OP
       2014-11-07 14:01:44 +08:00
    @yangg 不是很明白
    这个命令中的sudo,可以不用
    直接```su - -c 'll' other_user```
    或者```su -c 'll' other_user```
    也是一个意思,但是都不成功
    yangg
        3
    yangg  
       2014-11-07 14:17:44 +08:00
    试试,给你要执行的用户的bashrc里加上alais ll='ls -l'
    calebx
        4
    calebx  
    OP
       2014-11-07 14:18:56 +08:00
    在other_user的bashrc里面已经有这个alias了。。。
    extreme
        5
    extreme  
       2014-11-10 13:25:39 +08:00
    不太明白楼主的意思。

    不知道这种方式会不会导入另一个用户自己的.bashrc:
    sudo -u 用户名 bash -c "命令"

    或者试试这种方式:
    echo "source ~/.bashrc ; source ~/.profile ; 你要执行的命令" | sudo -u 用户名 bash -
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1570 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:08 · PVG 01:08 · LAX 10:08 · JFK 13:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.