击4关联数组:错误"声明:-A:无效选项" [英] Bash 4 associative arrays: error "declare: -A: invalid option"
问题描述
我已经写在bash中使用关联数组脚本(V 4)。
I've written a script that uses associative arrays in bash (v 4).
它正常工作,这是使用我的本地机器上的 4.1.5(1)-release
It works fine on my local machine which is using 4.1.5(1)-release
在生产机,使用 4.1.0(1)-release
下面的线,这声明数组assoc命令,失败:
On the production machine, using 4.1.0(1)-release
the following line, which declares the assoc array, fails:
declare -A uniqjars
与消息:
/script.sh: line 11: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
我是IM pression下,这是一个普通的bash 4功能?
I was under the impression this was a general bash 4 feature?
在男子bash的生产机器上,讨论使用的 -A 的,所以我认为它的应的工作。
In the man for bash on the production machine it discusses using -A so I assume it should work.
关联数组使用创建
声明-A名。
Associative arrays are created using declare -A name.
我可以确认脚本打印出的价值使用bash的正确版本回声的bash -version
I can confirm the script is using the right version of bash by printing out the value of echo 'bash -version
还有什么我做错了?
推荐答案
确认的bash的版本在shell脚本的顶部被援引作为跨preTER(#!/ bin中/庆典
或其他)也是4版本。如果你正在做的:
Make sure the version of bash being invoked as interpreter at the top of your shell script (#!/bin/bash
or whatever) is also version 4. If you're doing:
bash --version
和它给你V4,做一个这庆典
来检查它的位置。
and it's giving you v4, do a which bash
to check it's location.
这篇关于击4关联数组:错误"声明:-A:无效选项"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!