Last active
December 4, 2019 14:37
-
-
Save 1271/3f678ce34f0287f5414ca661e54b5e2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -gt 0 ] | |
then | |
max=$1 | |
max=$(( $max + 1 )) | |
else | |
max=200 | |
fi | |
echo '#!/bin/bash' | |
echo '' | |
echo " | |
if [ \$# -ne 1 ] | |
then | |
echo \"please, use \$0 \\\"1 + 3\\\"\" | |
exit 1 | |
fi | |
read -r -a P <<< "\$1" | |
i="\${P[0]}" | |
o="\${P[1]}" | |
j="\${P[2]}" | |
if [ \$i -lt 0 ] || [ \$i -gt $max ] | |
then | |
echo 'first num >= 0! AND <= $max' | |
exit 1 | |
fi | |
if [ \$j -lt 0 ] || [ \$j -gt $max ] | |
then | |
echo 'second num >= 0! AND <= $max' | |
exit 1 | |
fi | |
if [[ \"\$o\" != \"-\" && \"\$o\" != \"+\" && \"\$o\" != \"*\" && \"\$o\" != \"/\" ]] | |
then | |
echo 'operators allow: - + * /' | |
exit 1 | |
fi | |
" | |
i=0 | |
while (( $i < $max )) | |
do | |
j=0 | |
while (( j < $max )) | |
do | |
echo "if [ \$i -eq $i ] | |
then | |
if [ \$j -eq $j ] | |
then" | |
for o in {'+','-','*','/'} | |
do | |
echo " if [ \"\$o\" = \"$o\" ] | |
then" | |
if [ "$o" == "/" ] && [ $j -eq 0 ] | |
then | |
echo " echo \"Undefined\"" | |
else | |
echo " echo \"$(($i $o $j))\"" | |
fi | |
echo " fi" | |
done | |
echo " fi | |
fi | |
" | |
j=$(($j+1)) | |
done | |
i=$(($i+1)) | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Gunter Calculator]
OR