-
Notifications
You must be signed in to change notification settings - Fork 0
/
peu2degc
executable file
·95 lines (93 loc) · 2.79 KB
/
peu2degc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# This script's framework was created using makescript
# version v1.0.2, dated 2019-07-18
# Makescript and its accompanying scripts are copyrighted
# by Aetesaki (c) 2018
#
# peu2degc (c) 2019 aetesaki
#
# ##################################################
# HISTORY:
# ##################################################
#
# * 2019-07-19 - v0.0.0 - First Creation
# * 2019-07-19 - v0.0.1 - converting degf2degc to degc2degf
# * 2019-07-19 - v0.0.2 - renaming script variable to degc2degf
# * 2019-07-19 - v0.0.3 - converting degc2degf to degctopeu
# * 2019-07-19 - v0.0.4 - converting degc2peu to peu2degc
# * 2019-07-21 - v1.0.0 - release version
#
# ##################################################
# Initializing constants and variables
# ##################################################
# Setting constants
version="v1.0.0" # Sets version variable
lastEdited="2019-07-21" # Sets last edited variable
[ ! -t 0 ] && pipe=$(cat) # if stdin is open dump stdin to $pipe
# Declaring variables
declare peu celcius # temperature variables
# Declare all variables to be used in the script
# ##################################################
# short help function
# ##################################################
shorthelp() {
# Edit as required
cat << EOF
Usage: peu2degc [peu]
peu2degc --help
peu2degc --version"
EOF
}
# ##################################################
# no arguments gives short help
# ##################################################
if [ "$#" == "0" ]; then
# check if $pipe is empty
if [ -z "$pipe" ]; then
# display shorthelp and exit
shorthelp
exit 1
else
# else set arguments to $pipe
set -- "$pipe"
fi
fi
# ##################################################
# -- help
# ##################################################
if [ "$1" == "--help" ]; then
shorthelp
# Write options and explanations
cat << EOF
--help Displays this text and exit.
--version Displays the version of the script and exit.
EOF
# Write information on arguments afterwards
# Write examples as required
exit 0
fi
# ##################################################
# -- version
# ##################################################
if [ "$1" == "--version" ]; then
cat << EOF
peu2degc ${version}, dated ${lastEdited}
(c) 2019 aetesaki
EOF
exit 0
fi
# ##################################################
# Main section
# ##################################################
# Write your script here
# copy first argument to $peu
peu=$1
# Check for valid argument
if ! [[ $peu =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then
echo "Peu temperature measurement is not a number" >&2
exit 1
fi
# convert peu to celsius
celsius=$(awk "BEGIN {printf \"%.2f\n\", ($peu/0.8)+18}")
# echo the converted temperature
echo $celsius