如何在Unix(Bash)Shell脚本中使用带点的变量?我有以下脚本:
#!/bin/bash
set -x
"FILE=system.properties"
FILE=$1
echo $1
if [ -f "$FILE" ];
then
echo "File $FILE exists"
else
echo "File $FILE does not exist"
fi
基本上这就是我所需要的⟶ x=propertyfile
,propertyfile=$1.
有人可以帮我吗?
您不能用点声明变量名,但是可以使用关联数组来映射键,这是更合适的解决方案。这需要Bash 4.0。
declare -A FILE ## Declare variable as an associative array.
FILE[system.properties]="somefile" ## Assign a value.
echo "${FILE[system.properties]}" ## Access the value.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句