harryge
V2EX  ›  问与答

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

  •  
  •   harryge · Mar 4, 2019 · 1310 views
    This topic created in 2637 days ago, the information mentioned may be changed or developed.

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

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

    如果你想得到一样的体验的话,在 mac 上编译 gnu coreutils 然后 alias 到新的 binary 上就好了
    liubaicai
        2
    liubaicai  
       Mar 4, 2019   ❤️ 1
    brew install coreutils
    yuikns
        3
    yuikns  
       Mar 4, 2019
    要是只是 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  
       Mar 4, 2019 via iPhone
    PowerShell,在你的 profile 里添加 alias 使 rm 定向到 Remove-Item
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2643 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    ♥ Do have faith in what you're doing.