harryge
V2EX  ›  问与答

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

  •  
  •   harryge · Mar 4, 2019 · 1601 views
    This topic created in 2801 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
    Kirscheis
    Mar 4, 2019 via Android
    1
    程序如何处理 args 只和它自己有关,系统和 shell 不管这个。mac 和 linux 不同,是因为你在 mac 上用的是 BSD 的 rm,linux 上用的可能是 GNU 系的 rm。

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