Team,在一个关联数组中设置一些变量,但是它的输出没有产生任何结果。任何hint?>
#/bin/bash
#IOEngine="psync"
#TestType="read"
IOEngine="libaio"
TestType="randread"
vars_ioengine_defaults() {
declare -A associative_vars
RunTime="0"
UDCNAme="stage"
if [[ "$IOEnginge" == "psync" ]] && [[ "$TestType" == "read" ]]; then
declare -A associative_vars=([DFLT_QueueDepth]="0" [DFLT_DatasetSize]="3G" [DFLT_BlockSize]="2,4,8,16,32,64,128,256,512,1024" [DFLT_Threads]="1,2,4,8,16,32,64,128,256" [DFLT_FileSize]="3M")
elif [[ "$IOEngine" == "psync" ]] && [[ "$TestType" == "randread" ]]; then
declare -A associative_vars=([DFLT_QueueDepth]="0" [DFLT_DatasetSize]="1G" [DFLT_BlockSize]="8,16,32" [DFLT_Threads]="16,32,64,128,256" [DFLT_FileSize]="32k")
elif [[ "$IOEngine" == "libaio" ]] && [[ "$TestType" == "read" ]]; then
declare -A associative_vars=([DFLT_QueueDepth]="16" [DFLT_DatasetSize]="3G" [DFLT_BlockSize]="2,4,8,16,32,64,128,256,512,1024" [DFLT_Threads]="1,2,4,8,16,32,64,128,256" [DFLT_FileSize]="3M")
elif [[ "$IOEngine" == "libaio" ]] && [[ "$TestType" == "randread" ]]; then
declare -A associative_vars=([DFLT_QueueDepth]="16" [DFLT_DatasetSize]="1G" [DFLT_BlockSize]="8,16,32" [DFLT_Threads]="16,32,64,128,256" [DFLT_FileSize]="32k")
else
echo " Neither IOEngine nor TestType variables matched to required values"
fi
}
vars_ioengine_defaults
echo fio_gen ${associative_vars[DFLT_QueueDepth]} ${associative_vars[DFLT_DatasetSize]}产出:
prints nothing: no output here <<预期产出:
fio_gen 16 1G发布于 2019-06-11 01:58:16
您的变量仅在函数中可见。如果在主作用域中定义变量并分配函数中的值,它就可以工作:
#/bin/bash
#IOEngine="psync"
#TestType="read"
IOEngine="libaio"
TestType="randread"
declare -A associative_vars
vars_ioengine_defaults() {
RunTime="0"
UDCNAme="stage"
if [[ "$IOEnginge" == "psync" ]] && [[ "$TestType" == "read" ]]; then
associative_vars=([DFLT_QueueDepth]="0" [DFLT_DatasetSize]="3G" [DFLT_BlockSize]="2,4,8,16,32,64,128,256,512,1024" [DFLT_Threads]="1,2,4,8,16,32,64,128,256" [DFLT_FileSize]="3M")
elif [[ "$IOEngine" == "psync" ]] && [[ "$TestType" == "randread" ]]; then
associative_vars=([DFLT_QueueDepth]="0" [DFLT_DatasetSize]="1G" [DFLT_BlockSize]="8,16,32" [DFLT_Threads]="16,32,64,128,256" [DFLT_FileSize]="32k")
elif [[ "$IOEngine" == "libaio" ]] && [[ "$TestType" == "read" ]]; then
associative_vars=([DFLT_QueueDepth]="16" [DFLT_DatasetSize]="3G" [DFLT_BlockSize]="2,4,8,16,32,64,128,256,512,1024" [DFLT_Threads]="1,2,4,8,16,32,64,128,256" [DFLT_FileSize]="3M")
elif [[ "$IOEngine" == "libaio" ]] && [[ "$TestType" == "randread" ]]; then
associative_vars=([DFLT_QueueDepth]="16" [DFLT_DatasetSize]="1G" [DFLT_BlockSize]="8,16,32" [DFLT_Threads]="16,32,64,128,256" [DFLT_FileSize]="32k")
else
echo " Neither IOEngine nor TestType variables matched to required values"
fi
}
vars_ioengine_defaults
echo fio_gen ${associative_vars[DFLT_QueueDepth]} ${associative_vars[DFLT_DatasetSize]}https://unix.stackexchange.com/questions/524115
复制相似问题