Coreutils的GNU ls缺少OS X ACL实现 [英] GNU ls from Coreutils missing OS X ACL implementation

查看:94
本文介绍了Coreutils的GNU ls缺少OS X ACL实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用brew来检索并安装带有brew install coreutils的通用GNU版本的终端命令和实用程序.
然后在我的.bash_profile中,将他们的PATH包含在

I'm using brew to retrieve and install common GNU versions of terminal commands and utils with brew install coreutils.
Then in my .bash_profile I'm including their PATH with

if [  -d $(brew --prefix coreutils)/libexec/gnubin  ]; then
    PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"
fi

到目前为止,我可以使用使用GNU版本的coreutils.
问题来自ls.苹果工具在GNU ls上未实现的ACL .我是通过多次敲打头而不了解为什么(例如)ls -le@会给我错误ls: invalid option -- 'e'来发现这一点的.

so far so good, I can use use the GNU version of coreutils.
The problem comes from ls. Apple implement ACL that is not implemented on GNU ls. I discovered this by banging my head many times and not understanding why (for example) ls -le@ would give me error ls: invalid option -- 'e'.

所以现在我知道GNU ls是问题所在.

So now I understood that GNU ls is the problem.

问题:
如何获取所有coreutils BUT ls? 我想使用Apple版本的ls,但继续使用其余的coreutils.我该如何修改.bash_profile?

QUESTION:
how can I source all the coreutils BUT ls? I want to use the Apple version of ls but keep on using the rest of the coreutils. How can I achieve this modifying my .bash_profile?

如果我创建一个标志来了解我当前是否正在使用coretuils,那么我将创建一个别名:

If I create a flag to understand if I am currently using coretuils or not and as a consequence I'll create an alias:

ls_flag=false
if [[  $(brew) &&  -d  $(brew --prefix coreutils)/libexec/gnubin  ]]; then
    PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"
    ls_flag=true
fi

export PATH

if [[ ls_flag -eq true ]]; then
   alias ls=/bin/ls
fi

如果我在这里停止我的.bash_profile,这将起作用.但是另一个问题来自以下条件.我使用它们来了解我使用的是GNU ls还是Apple ls,并选择了正确的选项来使ls命令着色:

This will work if I stop my .bash_profile here. But another problem arise from the following conditions. I use them to understand if I'm using the GNU ls or the Apple ls and chose the correct option to colorise the ls command:

# Detect which `ls` flavour is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
    alias ls='ls --color=always'
    # load my color scheme (it only works with GNU ls)
    # dircolors only work with coreutils
    eval `dircolors  ~/.dotfiles/data/dircolors`
else # OS X `ls`
    alias ls='ls -G'
fi

因此,此时ls应该是:
1)别名ls =/bin/ls#从第一个条件开始ls_flag == true
2)别名ls ='ls -G'#来自第二个条件"if ls --color"(假)

So, at this point ls should be:
1) alias ls=/bin/ls # from the 1st condition ls_flag == true
2) alias ls='ls -G' # from the 2nd condition "if ls --color" (false)

但是如果我提示ls -@仍然会抛出一个错误,告诉我我仍在使用GNU ls ...想知道为什么最后一个别名会覆盖以前的别名...

BUT if I prompt ls -@ will still throw an error telling me that I'm still using the GNU ls...wondering why the last alias will override the previous ones...

推荐答案

这是错误的

if [[ ls_flag -eq true ]]; then
   alias ls=/bin/ls
fi

您缺少$ls_flag$,并且-eq用于[[ ... ]]

由于"true"和"false"是命令,因此您要编写

Since "true" and "false" are commands, you want to write

if $ls_flag; then
   alias ls=/bin/ls
fi

或更简洁

$ls_flag && alias ls=/bin/ls

这篇关于Coreutils的GNU ls缺少OS X ACL实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆