在Alpine 3.9上将正则表达式与运行部件一起使用

时间:2019-03-14 13:36:28

标签: regex alpine

我正在创建Docker映像FROM alpine:3.9.2,并且需要运行run-parts。我过去在ubuntu:16.04上使用下面的脚本没有问题。

 run-parts --verbose --regex '\.sh$' "$DIR"

但是,这一次,我在传递给它的选项上遇到了错误。即

  

run-parts:无法识别的选项:详细

     

run-parts:无法识别的选项:regex

根据我熟悉的Alpine 3.9.2,使用run-parts 4.8.6 https://pkgs.alpinelinux.org/package/edge/main/x86/run-partsdebianutils https://manpages.debian.org/testing/debianutils/run-parts.8.en.html并同时支持verboseregex

我在这里错过了什么吗?

如何在Alpine 3.9.2上运行所有以.sh结尾的文件?

1 个答案:

答案 0 :(得分:2)

默认情况下,高山图片中的run-parts版本非常裁剪。这是一个繁忙的信箱:

/ # which run-parts
/bin/run-parts
/ # run-parts --help
BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.

Usage: run-parts [-a ARG]... [-u UMASK] [--reverse] [--test] [--exit-on-error] DIRECTORY

Run a bunch of scripts in DIRECTORY

    -a ARG      Pass ARG as argument to scripts
    -u UMASK    Set UMASK before running scripts
    --reverse   Reverse execution order
    --test      Dry run
    --exit-on-error Exit if a script exits with non-zero

它只能在目录中运行一堆脚本。

如果要使用debianutils软件包中未切割的run-parts,则需要先将其安装到高山图像上:

/ # apk add --no-cache run-parts
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/1) Installing run-parts (4.8.6-r0)
Executing busybox-1.29.3-r10.trigger
OK: 6 MiB in 15 packages

现在,高山实例中有run-parts的完整版本:

/ # which run-parts
/usr/bin/run-parts
/ # run-parts --help
Usage: run-parts [OPTION]... DIRECTORY
      --test          print script names which would run, but don't run them.
      --list          print names of all valid files (can not be used with
                      --test)
  -v, --verbose       print script names before running them.
      --report        print script names if they produce output.
      --reverse       reverse execution order of scripts.
      --exit-on-error exit as soon as a script returns with a non-zero exit
                      code.
      --lsbsysinit    validate filenames based on LSB sysinit specs.
      --new-session   run each script in a separate process session
      --regex=PATTERN validate filenames based on POSIX ERE pattern PATTERN.
  -u, --umask=UMASK   sets umask to UMASK (octal), default is 022.
  -a, --arg=ARGUMENT  pass ARGUMENT to scripts, use once for each argument.
  -V, --version       output version information and exit.
  -h, --help          display this help and exit.