您的位置:首页 > 运维架构 > Shell

shell script 脚本传递参数的方法

2013-10-14 03:57 507 查看
shell 脚本中传递参数3种方法的比较

Bash里使用getopts解析非选项参数

在Shell脚本中处理命令行参数

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: