一个shell脚本引用变量的问题
#!/bin/shgetTiming(){start=$1end=$2start_s=$(echo$start|cut-d'.'-f1)start_ns=$(echo$s...
#!/bin/sh
getTiming()
{
start=$1
end=$2
start_s=$(echo $start | cut -d '.' -f 1)
start_ns=$(echo $start | cut -d '.' -f 2)
end_s=$(echo $end | cut -d '.' -f 1)
end_ns=$(echo $end | cut -d '.' -f 2)
# for debug..
echo $start
echo $end
time=$(( ( 10#$end_s - 10#$start_s ) * 1000 + ( 10#$end_ns / 1000000 - 10#$start_ns / 1000000 ) ))
echo "$time ms"
}
echo "This is only a test to get a ms level time duration..."
start=$(date +%s.%N)
ls >& /dev/null # hey, be quite, do not output to console....
end=$(date +%s.%N)
getTiming $start $end
这个shell脚本执行:inter.sh: syntax error at line 8: `start_s=$' unexpected
这是什么错误呢?不能这么用?Solaris系统,谢谢! 展开
getTiming()
{
start=$1
end=$2
start_s=$(echo $start | cut -d '.' -f 1)
start_ns=$(echo $start | cut -d '.' -f 2)
end_s=$(echo $end | cut -d '.' -f 1)
end_ns=$(echo $end | cut -d '.' -f 2)
# for debug..
echo $start
echo $end
time=$(( ( 10#$end_s - 10#$start_s ) * 1000 + ( 10#$end_ns / 1000000 - 10#$start_ns / 1000000 ) ))
echo "$time ms"
}
echo "This is only a test to get a ms level time duration..."
start=$(date +%s.%N)
ls >& /dev/null # hey, be quite, do not output to console....
end=$(date +%s.%N)
getTiming $start $end
这个shell脚本执行:inter.sh: syntax error at line 8: `start_s=$' unexpected
这是什么错误呢?不能这么用?Solaris系统,谢谢! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |