-
Notifications
You must be signed in to change notification settings - Fork 0
/
degc2degf
executable file
·92 lines (90 loc) · 2.7 KB
/
degc2degf
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
#!/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
#
# degc2degf (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
#
# ##################################################
# Initializing constants and variables
# ##################################################
# Setting constants
version="v0.0.2" # Sets version variable
lastEdited="2019-07-19" # Sets last edited variable" $scriptNamePath
[ ! -t 0 ] && pipe=$(cat) # if stdin is open dump stdin to $pipe
# Declaring variables
declare fahrenheit celcius # temperature variables
# Declare all variables to be used in the script
# ##################################################
# short help function
# ##################################################
shorthelp() {
# Edit as required
cat << EOF
Usage: degc2degf [celsius]
degc2degf --help
degc2degf --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
degc2degf ${version}, dated ${lastEdited}
(c) 2019 aetesaki
EOF
exit 0
fi
# ##################################################
# Main section
# ##################################################
# Write your script here
# copy first argument to $celcius
celsius=$1
# Check for valid argument
if ! [[ $celsius =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then
echo "Celsius temperature measurement is not a number" >&2
exit 1
fi
# convert celsius to fahrenheit
fahrenheit=$(awk "BEGIN {printf \"%.2f\n\", ($celsius*(9/5))+32}")
# echo the converted temperature
echo $fahrenheit