PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Calculating Distance With Bash In Linux

Go down

Calculating Distance With Bash In Linux Empty Calculating Distance With Bash In Linux

Post by jamied_uk 8th June 2022, 11:44




Code:
#!/bin/bash
# (c)J~Net 2022
# jnet.sytes.net
#
# ./calc.sh
#
f="1.609344" # convertion factor
echo "Welcome To The J~Net Distance Calculator 2022"
echo ""
echo "Please Enter Speed In KPH"
read s
echo "You Entered $s"
echo ""
echo "Enter Time In Minutes"
read t
echo "You Entered $t"
echo ""
final=$((s * t))
#
offset='0.000001'
echo $final > file
#printf "%s+%s\n" $(tail -1 file) "$offset" | bc
read -r -n 1 output < file # read 1st char from text file
tail -c +2 file > file.txt # read everything else except 1st char from text file
last=`cat file.txt` # read a text file into a bash var
echo "Distance Is $output.$last Miles"

echo ""
echo "$s/$f" | bc > output.txt # Convert kph to mph
output=`cat output.txt`
echo "Also You Went $output Miles Per Hour!"

echo ""
rm file && rm file.txt && rm output.txt
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum