首页 > 解决方案 > \! 是什么意思?意思是?寻找 。\!-user redis -exec chown redis '{}' +

问题描述

关于 redis docker 镜像ENTRYPOINT脚本docker-entrypoint.sh

#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
# or first arg is `something.conf`
if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
        set -- redis-server "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
        find . \! -user redis -exec chown redis '{}' +
        exec gosu redis "$0" "$@"
fi

exec "$@"

在以下行中:

find . \! -user redis -exec chown redis '{}' +

是什么\!意思?

标签: dockershellfindsh

解决方案


根据GNU find 文档,您可以同时使用! <expr>-not <expr>交替使用来匹配与表达式不匹配的项目:

2.11 将基本元素与运算符结合起来

expr
- 不是expr

如果expr为假,则为真。在某些 shell 中,有必要保护 '!' 通过引用它来自shell解释。

反斜杠 ( \) 用于多个 shell,例如 Bourne-Again Shell ( bash),以转义具有特殊含义的保留字符,这些字符不是由 shell 逐字评估的,感叹号( !) 字符就是这种情况。

在这种情况下,正如@ottomeister 在他的评论中已经提到的那样,这个命令将应用于chown redis <item>从当前目录递归找到的所有项目,其所有者还不是 redis。


推荐阅读