实用脚本工具集:温度转换、贷款计算与日程管理
1. 脚本编程基础与温度转换脚本
在脚本编程中,很多命令行工具能实现的功能,脚本也能做到。例如在 bc 命令行能完成的数学计算,在脚本中同样可以,但 calc.sh 脚本没有逐行记忆和状态保留功能。不过,这也意味着我们可以根据需求为帮助系统添加更多数学函数。
1.1 温度转换脚本 convertatemp
温度转换脚本 convertatemp 是一个实用的工具,它能在华氏度(Fahrenheit)、摄氏度(Celsius)和开尔文(Kelvin)三种温度单位之间进行转换。以下是具体代码:
#!/bin/bash
# convertatemp--Temperature conversion script that lets the user enter
# a temperature in Fahrenheit, Celsius, or Kelvin and receive the
# equivalent temperature in the other two units as the output
if [ $# -eq 0 ] ; then
cat << EOF >&2
Usage: $0 temperature[F|C|K]
where the suffix:
F indicates input is in Fahrenheit (default)
C indi
超级会员免费看
订阅专栏 解锁全文
1285

被折叠的 条评论
为什么被折叠?



