【发布时间】:2022-01-03 20:37:17
【问题描述】:
现状
我有一个外部属性文件,其中存储了几个变量。其中之一有一个值列表(最小 1 个值,最大 X 个值)。
在 shell 脚本中声明这个单一列表时,它看起来像这样:
NODES=(
"node"
"node-2"
"node-3"
)
我像这样从属性文件中读取值:
# checks, if file exists and is readable
file="./properties.credo"
if [ ! -r "$file" ]
then
echo "fatal: properties file $file not found / readable."
exit 2
fi
# loads properties into variables
. $file
[[ -z "$VALUEA" ]] && echo "fatal: VALUEA not specified in .credo" && exit 2
...
问题
在这样的属性中定义节点值时:
NODES=node,node-2,node-3
...然后阅读:
...
[[ -z "$NODES" ]] && echo "fatal: NODES not specified in .credo" && exit 2
...
...它将作为单个字符串node,node-2,node-3 从文件中读取,而不是作为列表或一维数组。
【问题讨论】:
-
尝试删除 $NODES 周围的引号
标签: arrays bash list file-handling