Skip to content

Instantly share code, notes, and snippets.

@1271
Last active December 4, 2019 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1271/3f678ce34f0287f5414ca661e54b5e2b to your computer and use it in GitHub Desktop.
Save 1271/3f678ce34f0287f5414ca661e54b5e2b to your computer and use it in GitHub Desktop.
#!/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
@1271
Copy link
Author

1271 commented Nov 18, 2016

[Gunter Calculator]

  1. chmod run access:
 [ ololosha-host@ololosha /home/ololosha/ ] chmod a+x ./gunter_generator.sh;
  1. generate gunter:
 [ ololosha-host@ololosha /home/ololosha/ ] ./gunter_generator.sh > gunter.sh; chmod a+x gunter.sh

OR

 [ ololosha-host@ololosha /home/ololosha/ ] ./gunter_generator.sh 427 > gunter.sh; chmod a+x gunter.sh
  1. run gunter:
 [ ololosha-host@ololosha /home/ololosha/ ] ./gunter.sh 5 / 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment