求教:$sudo su -c 'll' other_user ... error: command not found - V2EX
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 3175 次点击
    这是一个创建于 4039 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想在当前用户下,切换到另外一个用户,并且执行一些命令。
    这些命令有.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 -
    关于   span class="snow">   帮助文档     自助推广系统     博客     API     FAQ     Solana     869 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 21ms UTC 22:17 PVG 06:17 LAX 14:17 JFK 17:17
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86