我为什么要获得未绑定的变量?

时间:2015-05-13 22:49:01

标签: bash

我有以下脚本,它在大多数情况下都有效,直到遇到特定的行:

#!/usr/bin/env bash

set -eux

# Go Home.
cd /vagrant/Freya/

CLEANED_ASSETS=false

## Clean up time!
## Remove all vendor and composer.lock folders - just because.
for f in *; do
  if [[ -d $f ]]; then
    if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; then

      if [[ $f == "Loader" ]] && [[ $CLEANED_ASSETS == false ]]; then
        cd "$f/"
        if [[ -d "Assets" ]]; then
          cd Assets/
          rm -rf vendor composer.lock docs
          let $CLEANED_ASSETS=true
          cd ../../
        fi
      fi

      cd "$f/"
      rm -rf vendor composer.lock docs
      cd ../
    fi
  fi
done

问题是它何时命中let $CLEANED_ASSETS=true我不确定将此变量设置为true的正确方法,因此它永远不会再次进入此循环。我一直在说:

+ let false=true
bin/clean-directories: line 21: true: unbound variable

1 个答案:

答案 0 :(得分:3)

CLEANED_ASSETS=true

let,没有$

特别是,let导致true被视为变量名称(搜索数值),并且引用不存在的变量名称会被{{1 }}