Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在要排除的循环中grep?_Linux_Bash_Shell_Sh - Fatal编程技术网

Linux 如何在要排除的循环中grep?

Linux 如何在要排除的循环中grep?,linux,bash,shell,sh,Linux,Bash,Shell,Sh,我有一个NPM_RESERVED_作用域,它包含一个逗号分隔的禁止作用域列表 我有一个NPM_ALLOWED_DEV_DEPENDENCIES_包,其中包含一个逗号分隔的异常列表 NPM_RESERVED_SCOPE=@privatescope,@secondary NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES="@privatescope/private-project-scripts,@privatescope/private-project-ci-build,

我有一个NPM_RESERVED_作用域,它包含一个逗号分隔的禁止作用域列表

我有一个NPM_ALLOWED_DEV_DEPENDENCIES_包,其中包含一个逗号分隔的异常列表

NPM_RESERVED_SCOPE=@privatescope,@secondary
NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES="@privatescope/private-project-scripts,@privatescope/private-project-ci-build,@privatescope/private-project-ci-test,@privatescope/private-project-ci-release,@privatescope/private-project-ci-deploy,@privatescope/private-project-ci-release-transitive"


for i in $(echo ${NPM_RESERVED_SCOPES} | sed "s/,/ /g")
  do
    for j in $(echo ${NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES} | sed "s/,/ /g")
    do
      if [[ $(cat package.json | jq .devDependencies | grep "$i/" | grep -v "$j") ]]; then
        echo "[Error] GitHub release abort. Reason: devDependencies within scope $i are forbidden."
        exit 1
      fi
    done
  done
如果devdependences不包含任何NPM_RESERVED_作用域(异常列表除外),我希望此脚本通过

NPM_RESERVED_SCOPE=@privatescope,@secondary
NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES="@privatescope/private-project-scripts,@privatescope/private-project-ci-build,@privatescope/private-project-ci-test,@privatescope/private-project-ci-release,@privatescope/private-project-ci-deploy,@privatescope/private-project-ci-release-transitive"


for i in $(echo ${NPM_RESERVED_SCOPES} | sed "s/,/ /g")
  do
    for j in $(echo ${NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES} | sed "s/,/ /g")
    do
      if [[ $(cat package.json | jq .devDependencies | grep "$i/" | grep -v "$j") ]]; then
        echo "[Error] GitHub release abort. Reason: devDependencies within scope $i are forbidden."
        exit 1
      fi
    done
  done
这是package.json文件


我该怎么做?

将列表转换为扩展模式,方法是将列表替换为|,并用@包装

现在模式匹配可以替换嵌套的for循环。如果a匹配任何一个模式x、y或z,则a=@x | y | z


请为我刚才做的文件ok@dawg的示例添加广告。
reserved="@(${NPM_RESERVED_SCOPE//,/|})"
allowed="@(${NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES//,/|})"
while IFS= read -r dep; do
  if [[ $dep = $reserved && $dep != $allowed ]]; then
      echo "[Error] GitHub release abort. Reason: $dep within scope $i is forbidden." >&2
      exit 1
  fi
done < <( jq .devDependencies '.devDependencies' )