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

2019-03-04 15:52:27 +08:00
 harryge

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

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

如果你想得到一样的体验的话,在 mac 上编译 gnu coreutils 然后 alias 到新的 binary 上就好了
liubaicai
2019-03-04 16:25:04 +08:00
brew install coreutils
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
2019-03-04 16:33:01 +08:00
PowerShell,在你的 profile 里添加 alias 使 rm 定向到 Remove-Item

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/540896

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX