Bash里使用getopts解析非选项参数
By reading from a configuration file:
PINTOOL obj-ia32/cacheSim3.so mode 0 nL1 16 nL1Set 256 nBlockPerL1Set 1 nL2 1 nL2Set 16384 nBlockPerL2Set 16 nStoreBuffer 64 emitTrace 0 coherenceMode D L1Latency 2 L2Latency 10 MemoryLatency 300
#!/bin/sh if [ $# -lt 1 ]; then echo "Usage: $0 <configure>" exit fi ################################################ # Pin Parameters, read from configuration file ################################################ while read line do #echo $line key=`echo $line |awk {'print $1'}` val=`echo $line |awk {'print $2'}` echo $key $val case "$key" in PINTOOL) PINTOOL=$val;; mode) mode=$val;; nL1) nL1=$val;; nL1Set) nL1Set=$val;; nBlockPerL1Set) nBlockPerL1Set=$val;; nL2) nL2=$val;; nL2Set) nL2Set=$val;; nBlockPerL2Set) nBlockPerL2Set=$val;; nStoreBuffer) nStoreBuffer=$val;; emitTrace) emitTrace=$val;; coherenceMode) coherenceMode=$val;; L1Latency) L1Latency=$val;; L2Latency) L2Latency=$val;; MemoryLatency) MemoryLatency=$val;; *) echo "Sorry, $key not recognized ..." exit 1;; esac done < $1 RunCacheCore="pin -t $PINTOOL -l1c $nL1 -l1s $nL1Set -l1b $nBlockPerL1Set -l2c $nL2 -l2s $nL2Set -l2b $nBlockPerL2Set -sbd $nStoreBuffer -trace $emitTrace -coh $coherenceMode -l1lat $L1Latency -l2lat $L2Latency -memlat $MemoryLatency" ################################# # Global Application Parameters ################################# RESULTS=results [[ ! -d $RESULTS ]] && mkdir -p $RESULTS np=4