local:-n:无效选项

时间:2016-10-25 10:38:26

标签: bash ubuntu

使用./script执行脚本时,我看到了 local:-n:无效选项

我的测试脚本:cat script

#!/bin/bash

declare -Ax BINS_TO_ARCH_FILE=(
 ["file1"]="test/file1"
 ["file2"]="test/file2"
 ["file3"]="test/file3"
);

function archive-bz2()
{
  local -n DO_NOT_USE_THIS_NAME="$1";

  for path_to_archive in "${!DO_NOT_USE_THIS_NAME[@]}"; do
    echo "path_to_archive: $path_to_archive";
  done
}

archive-bz2 BINS_TO_ARCH_FILE

但是当我在

的子shell中执行它时
bash script

它正在运作......

echo $SHELL
/bin/bash

bash --version
GNU bash, version 4.4.0(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

我使用较旧的bash版本测试了它,并且两种方式都正常工作:( 在本地都是建立命令

type local
local is a shell builtin

bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

0 个答案:

没有答案