一个非常简单的shell脚本--计算打的费用

上一篇 / 下一篇  2010-02-10 14:10:37 / 个人分类:linux

#!/bin/bash

#计算一个简单的出租车费用

dir=/home/qjy/zouxc/example

#初始化变量

DATE=`date +%Y-%m-%d_%H:%M:%S`

user_log=$dir/user_log

total_price=0

#清空日志

cat /dev/null>user_log

echo " ------------------ $DATE ------------------- ">$user_log

echo "请输入总的车程: \c"

read total_distance

echo "请输入起步价start_price及起步路程start_distance:\c"

read start_price start_distance

echo "请输入超出起步价后的价格other_price: \c"

read other_price

if [ "$total_distance"  -le "$start_distance" ] ; then

        total_price=$start_price

else

        total_price=`expr $start_price +\($total_distance-$start_distance\) \* $other_price`

fi

echo $total_price

echo "您的出租车费用价格为 $total_price">>$user_log

 

输出:

[zxc@1363 example]$ cat user_log

 ------------------ 2010-02-08_21:47:45 -------------------

您的出租车费用价格为 3


TAG: shell Shell

 

评分:0

我来说两句

日历

« 2024-04-26  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 6516
  • 日志数: 8
  • 建立时间: 2010-01-20
  • 更新时间: 2010-04-01

RSS订阅

Open Toolbar