Bash Script Wind Chill using getopt and bc












0















Thanks to Fox I am now getting the correct output, however it is not scaling to only 3 places. Anyone know how to do that?



function windchill {
to=32
v=10
vel=`echo 'e(l('$v')*0.16)' | bc -l`
w=$(echo "scale=3; $vel" | bc -l)
twc=`echo "35.74 + (0.6215 * $to) - (35.75 * $w) + (0.4275 * $to * $w)" | bc`
echo ''
echo 'Windchill Calculator'
echo 'Outside Air Temperature (F): '"$to"
echo 'Wind Speed: '"$v"
echo 'Wind-Chill (F): '"$twc"
echo ''
exit
}


I am getting the correct $tf and $v the $wc is my problem. Using a calculator I get the correct answer just not in my bash file. The problem is my $w is coming back as a 1 not 1.4454.



The next area is the getopt to my case switch and the values aren't being passed from the input to the function



ARGS=$(getopt -o "chqv" -l "airtemp=$temp::,velocity=$speed::,cout:,cin:,file=$filename:,help,quiet:,version" -- "$@")
eval set -- "$ARGS"

# handle options
while true; do
case "$1" in
--airtemp=$temp)
temp=$temp
windchill
shift;;

--velocity=$speed)
speed=$speed
windchill
shift;;

-c | --cout)
cout
shift;;

--cin)
cin
shift;;

--file=$filename)
file
shift;;

-h | --help)
help
exit;;

-q | --quiet)
quiet
shift;;

-v | --version)
version
exit;;

*)
echo "Illegal Input"
exit
esac


done



exit










share|improve this question

























  • I don't quite nee why you call windchill inside the option parsing loop, ofter setting speed and temp. Wouldn't you want to set all parameters and then call windchill after the loop?

    – Kusalananda
    1 hour ago











  • I was under the impression that the shift means it would check the first one and then shift to the next one. I completely guessing on how to do this. My professor gave me a web site and said figure it out. linuxaria.com/howto/… this is what he gave us as a reference

    – Trinity Zamrzla
    1 hour ago


















0















Thanks to Fox I am now getting the correct output, however it is not scaling to only 3 places. Anyone know how to do that?



function windchill {
to=32
v=10
vel=`echo 'e(l('$v')*0.16)' | bc -l`
w=$(echo "scale=3; $vel" | bc -l)
twc=`echo "35.74 + (0.6215 * $to) - (35.75 * $w) + (0.4275 * $to * $w)" | bc`
echo ''
echo 'Windchill Calculator'
echo 'Outside Air Temperature (F): '"$to"
echo 'Wind Speed: '"$v"
echo 'Wind-Chill (F): '"$twc"
echo ''
exit
}


I am getting the correct $tf and $v the $wc is my problem. Using a calculator I get the correct answer just not in my bash file. The problem is my $w is coming back as a 1 not 1.4454.



The next area is the getopt to my case switch and the values aren't being passed from the input to the function



ARGS=$(getopt -o "chqv" -l "airtemp=$temp::,velocity=$speed::,cout:,cin:,file=$filename:,help,quiet:,version" -- "$@")
eval set -- "$ARGS"

# handle options
while true; do
case "$1" in
--airtemp=$temp)
temp=$temp
windchill
shift;;

--velocity=$speed)
speed=$speed
windchill
shift;;

-c | --cout)
cout
shift;;

--cin)
cin
shift;;

--file=$filename)
file
shift;;

-h | --help)
help
exit;;

-q | --quiet)
quiet
shift;;

-v | --version)
version
exit;;

*)
echo "Illegal Input"
exit
esac


done



exit










share|improve this question

























  • I don't quite nee why you call windchill inside the option parsing loop, ofter setting speed and temp. Wouldn't you want to set all parameters and then call windchill after the loop?

    – Kusalananda
    1 hour ago











  • I was under the impression that the shift means it would check the first one and then shift to the next one. I completely guessing on how to do this. My professor gave me a web site and said figure it out. linuxaria.com/howto/… this is what he gave us as a reference

    – Trinity Zamrzla
    1 hour ago
















0












0








0








Thanks to Fox I am now getting the correct output, however it is not scaling to only 3 places. Anyone know how to do that?



function windchill {
to=32
v=10
vel=`echo 'e(l('$v')*0.16)' | bc -l`
w=$(echo "scale=3; $vel" | bc -l)
twc=`echo "35.74 + (0.6215 * $to) - (35.75 * $w) + (0.4275 * $to * $w)" | bc`
echo ''
echo 'Windchill Calculator'
echo 'Outside Air Temperature (F): '"$to"
echo 'Wind Speed: '"$v"
echo 'Wind-Chill (F): '"$twc"
echo ''
exit
}


I am getting the correct $tf and $v the $wc is my problem. Using a calculator I get the correct answer just not in my bash file. The problem is my $w is coming back as a 1 not 1.4454.



The next area is the getopt to my case switch and the values aren't being passed from the input to the function



ARGS=$(getopt -o "chqv" -l "airtemp=$temp::,velocity=$speed::,cout:,cin:,file=$filename:,help,quiet:,version" -- "$@")
eval set -- "$ARGS"

# handle options
while true; do
case "$1" in
--airtemp=$temp)
temp=$temp
windchill
shift;;

--velocity=$speed)
speed=$speed
windchill
shift;;

-c | --cout)
cout
shift;;

--cin)
cin
shift;;

--file=$filename)
file
shift;;

-h | --help)
help
exit;;

-q | --quiet)
quiet
shift;;

-v | --version)
version
exit;;

*)
echo "Illegal Input"
exit
esac


done



exit










share|improve this question
















Thanks to Fox I am now getting the correct output, however it is not scaling to only 3 places. Anyone know how to do that?



function windchill {
to=32
v=10
vel=`echo 'e(l('$v')*0.16)' | bc -l`
w=$(echo "scale=3; $vel" | bc -l)
twc=`echo "35.74 + (0.6215 * $to) - (35.75 * $w) + (0.4275 * $to * $w)" | bc`
echo ''
echo 'Windchill Calculator'
echo 'Outside Air Temperature (F): '"$to"
echo 'Wind Speed: '"$v"
echo 'Wind-Chill (F): '"$twc"
echo ''
exit
}


I am getting the correct $tf and $v the $wc is my problem. Using a calculator I get the correct answer just not in my bash file. The problem is my $w is coming back as a 1 not 1.4454.



The next area is the getopt to my case switch and the values aren't being passed from the input to the function



ARGS=$(getopt -o "chqv" -l "airtemp=$temp::,velocity=$speed::,cout:,cin:,file=$filename:,help,quiet:,version" -- "$@")
eval set -- "$ARGS"

# handle options
while true; do
case "$1" in
--airtemp=$temp)
temp=$temp
windchill
shift;;

--velocity=$speed)
speed=$speed
windchill
shift;;

-c | --cout)
cout
shift;;

--cin)
cin
shift;;

--file=$filename)
file
shift;;

-h | --help)
help
exit;;

-q | --quiet)
quiet
shift;;

-v | --version)
version
exit;;

*)
echo "Illegal Input"
exit
esac


done



exit







bash bc getopts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 58 mins ago







Trinity Zamrzla

















asked 2 hours ago









Trinity ZamrzlaTrinity Zamrzla

295




295













  • I don't quite nee why you call windchill inside the option parsing loop, ofter setting speed and temp. Wouldn't you want to set all parameters and then call windchill after the loop?

    – Kusalananda
    1 hour ago











  • I was under the impression that the shift means it would check the first one and then shift to the next one. I completely guessing on how to do this. My professor gave me a web site and said figure it out. linuxaria.com/howto/… this is what he gave us as a reference

    – Trinity Zamrzla
    1 hour ago





















  • I don't quite nee why you call windchill inside the option parsing loop, ofter setting speed and temp. Wouldn't you want to set all parameters and then call windchill after the loop?

    – Kusalananda
    1 hour ago











  • I was under the impression that the shift means it would check the first one and then shift to the next one. I completely guessing on how to do this. My professor gave me a web site and said figure it out. linuxaria.com/howto/… this is what he gave us as a reference

    – Trinity Zamrzla
    1 hour ago



















I don't quite nee why you call windchill inside the option parsing loop, ofter setting speed and temp. Wouldn't you want to set all parameters and then call windchill after the loop?

– Kusalananda
1 hour ago





I don't quite nee why you call windchill inside the option parsing loop, ofter setting speed and temp. Wouldn't you want to set all parameters and then call windchill after the loop?

– Kusalananda
1 hour ago













I was under the impression that the shift means it would check the first one and then shift to the next one. I completely guessing on how to do this. My professor gave me a web site and said figure it out. linuxaria.com/howto/… this is what he gave us as a reference

– Trinity Zamrzla
1 hour ago







I was under the impression that the shift means it would check the first one and then shift to the next one. I completely guessing on how to do this. My professor gave me a web site and said figure it out. linuxaria.com/howto/… this is what he gave us as a reference

– Trinity Zamrzla
1 hour ago












1 Answer
1






active

oldest

votes


















1














In bc, the ^ operator is integer exponentiation, so you're actually raising v to the 0 power, not 0.16. You can make use of logarithms to compute general exponents though: instead of x^y, you can use e(y*l(x)). So here, instead of v^0.16, you'll want e(0.16*l(v)).



Note that this requires the -l option to bc to include the standard math library.






share|improve this answer
























  • okay thanks for the help I got this to work however I need it only the the 3rd digit after the decimal vel=echo 'e(l('$v')*0.16)' | bc -l

    – Trinity Zamrzla
    1 hour ago













  • That's what scale is for

    – Fox
    1 hour ago











  • I have tried and I am still getting a long output, maybe I am not inputting it correctly. w=$(echo "scale=3; $vel" | bc -l) and my output is 1.44543977074592751192

    – Trinity Zamrzla
    58 mins ago











  • w=$(echo "scale=3; e(0.16 * l($v))" | bc -l) works for me, at least for setting w correctly

    – Fox
    7 mins ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505229%2fbash-script-wind-chill-using-getopt-and-bc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In bc, the ^ operator is integer exponentiation, so you're actually raising v to the 0 power, not 0.16. You can make use of logarithms to compute general exponents though: instead of x^y, you can use e(y*l(x)). So here, instead of v^0.16, you'll want e(0.16*l(v)).



Note that this requires the -l option to bc to include the standard math library.






share|improve this answer
























  • okay thanks for the help I got this to work however I need it only the the 3rd digit after the decimal vel=echo 'e(l('$v')*0.16)' | bc -l

    – Trinity Zamrzla
    1 hour ago













  • That's what scale is for

    – Fox
    1 hour ago











  • I have tried and I am still getting a long output, maybe I am not inputting it correctly. w=$(echo "scale=3; $vel" | bc -l) and my output is 1.44543977074592751192

    – Trinity Zamrzla
    58 mins ago











  • w=$(echo "scale=3; e(0.16 * l($v))" | bc -l) works for me, at least for setting w correctly

    – Fox
    7 mins ago
















1














In bc, the ^ operator is integer exponentiation, so you're actually raising v to the 0 power, not 0.16. You can make use of logarithms to compute general exponents though: instead of x^y, you can use e(y*l(x)). So here, instead of v^0.16, you'll want e(0.16*l(v)).



Note that this requires the -l option to bc to include the standard math library.






share|improve this answer
























  • okay thanks for the help I got this to work however I need it only the the 3rd digit after the decimal vel=echo 'e(l('$v')*0.16)' | bc -l

    – Trinity Zamrzla
    1 hour ago













  • That's what scale is for

    – Fox
    1 hour ago











  • I have tried and I am still getting a long output, maybe I am not inputting it correctly. w=$(echo "scale=3; $vel" | bc -l) and my output is 1.44543977074592751192

    – Trinity Zamrzla
    58 mins ago











  • w=$(echo "scale=3; e(0.16 * l($v))" | bc -l) works for me, at least for setting w correctly

    – Fox
    7 mins ago














1












1








1







In bc, the ^ operator is integer exponentiation, so you're actually raising v to the 0 power, not 0.16. You can make use of logarithms to compute general exponents though: instead of x^y, you can use e(y*l(x)). So here, instead of v^0.16, you'll want e(0.16*l(v)).



Note that this requires the -l option to bc to include the standard math library.






share|improve this answer













In bc, the ^ operator is integer exponentiation, so you're actually raising v to the 0 power, not 0.16. You can make use of logarithms to compute general exponents though: instead of x^y, you can use e(y*l(x)). So here, instead of v^0.16, you'll want e(0.16*l(v)).



Note that this requires the -l option to bc to include the standard math library.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 hours ago









FoxFox

5,55711233




5,55711233













  • okay thanks for the help I got this to work however I need it only the the 3rd digit after the decimal vel=echo 'e(l('$v')*0.16)' | bc -l

    – Trinity Zamrzla
    1 hour ago













  • That's what scale is for

    – Fox
    1 hour ago











  • I have tried and I am still getting a long output, maybe I am not inputting it correctly. w=$(echo "scale=3; $vel" | bc -l) and my output is 1.44543977074592751192

    – Trinity Zamrzla
    58 mins ago











  • w=$(echo "scale=3; e(0.16 * l($v))" | bc -l) works for me, at least for setting w correctly

    – Fox
    7 mins ago



















  • okay thanks for the help I got this to work however I need it only the the 3rd digit after the decimal vel=echo 'e(l('$v')*0.16)' | bc -l

    – Trinity Zamrzla
    1 hour ago













  • That's what scale is for

    – Fox
    1 hour ago











  • I have tried and I am still getting a long output, maybe I am not inputting it correctly. w=$(echo "scale=3; $vel" | bc -l) and my output is 1.44543977074592751192

    – Trinity Zamrzla
    58 mins ago











  • w=$(echo "scale=3; e(0.16 * l($v))" | bc -l) works for me, at least for setting w correctly

    – Fox
    7 mins ago

















okay thanks for the help I got this to work however I need it only the the 3rd digit after the decimal vel=echo 'e(l('$v')*0.16)' | bc -l

– Trinity Zamrzla
1 hour ago







okay thanks for the help I got this to work however I need it only the the 3rd digit after the decimal vel=echo 'e(l('$v')*0.16)' | bc -l

– Trinity Zamrzla
1 hour ago















That's what scale is for

– Fox
1 hour ago





That's what scale is for

– Fox
1 hour ago













I have tried and I am still getting a long output, maybe I am not inputting it correctly. w=$(echo "scale=3; $vel" | bc -l) and my output is 1.44543977074592751192

– Trinity Zamrzla
58 mins ago





I have tried and I am still getting a long output, maybe I am not inputting it correctly. w=$(echo "scale=3; $vel" | bc -l) and my output is 1.44543977074592751192

– Trinity Zamrzla
58 mins ago













w=$(echo "scale=3; e(0.16 * l($v))" | bc -l) works for me, at least for setting w correctly

– Fox
7 mins ago





w=$(echo "scale=3; e(0.16 * l($v))" | bc -l) works for me, at least for setting w correctly

– Fox
7 mins ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505229%2fbash-script-wind-chill-using-getopt-and-bc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

宮崎県

濃尾地震

6月16日