チーム、連想配列にいくつかの変数を設定しましたが、出力は結果を生成しません。ヒントがありますか? >
#/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
答え1
変数は関数内でのみ表示されます。デフォルトの範囲で変数を定義し、関数に値を割り当てると機能します。
#/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]}