V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
harryge
V2EX  ›  问与答

mac shell 中如何把 options 后置?比如 ls . -la

  •  
  •   harryge · 2019-03-04 15:52:27 +08:00 · 899 次点击
    这是一个创建于 1884 天前的主题,其中的信息可能已经有所发展或是发生改变。

    希望与 linux 相同,有时会在敲了 rm /directory/abc/ 之后才想起要 -rf,mac 里

    # rm /abc/def -rf                        
    rm: -rf: No such file or directory
    
    4 条回复    2019-03-04 16:33:01 +08:00
    Kirscheis
        1
    Kirscheis  
       2019-03-04 16:05:44 +08:00 via Android
    程序如何处理 args 只和它自己有关,系统和 shell 不管这个。mac 和 linux 不同,是因为你在 mac 上用的是 BSD 的 rm,linux 上用的可能是 GNU 系的 rm。

    如果你想得到一样的体验的话,在 mac 上编译 gnu coreutils 然后 alias 到新的 binary 上就好了
    liubaicai
        2
    liubaicai  
       2019-03-04 16:25:04 +08:00   ❤️ 1
    brew install coreutils
    yuikns
        3
    yuikns  
       2019-03-04 16:27:08 +08:00
    要是只是 ls 的话,可以自己某处写个 wrapper 如下。

    #!/bin/sh
    args=()
    flgs=("-G")
    for opt; do
    case "$opt" in
    -*) flgs=("${flgs[@]}" $opt);;
    *) args=("${args[@]}" $opt);;
    esac
    done
    exec /bin/ls "${flgs[@]}" "${args[@]}"



    rm 等皆类似。
    geelaw
        4
    geelaw  
       2019-03-04 16:33:01 +08:00 via iPhone
    PowerShell,在你的 profile 里添加 alias 使 rm 定向到 Remove-Item
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4968 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:32 · PVG 17:32 · LAX 02:32 · JFK 05:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.