Backward compatibility issue with GNU bash, version 4.3.42(5)

Hi,

I have made a snake game on below bash version. But it is not backward compatible. Can someone suggest a version which is most commonly used and
is backward compatible so that i can change my code and share again?
I have attached the game script. If someone can run it please also suggest improvements and new ideas

GNU bash, version 4.3.42(5)-release (x86_64-pc-msys)

Thanks,
Amit

There are lots of systems like Solaris 10 that are going to be way back - at 3.3 bash, for example.

So, what do you want to do? I would try ksh88 which is close to Linux pdksh. Most systems have that as a fall back. You can also download older versions of bash if you want.

KornShell -> to download ksh 88.

Earlier bash: Index of /gnu/bash
I do not know how well early bash versions like 1.14 behave in new environments.

1 Like

Jim mentioned Solaris 10. The version of bash running on the latest release of macOS ( macOS Sierra Version 10.12.4 ) is even older:

GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.
1 Like

Thank you. I'll download 3.2.57(1) version and change code accordingly..

I'm facing problems with array and read options from keyboard which runs fine on my machine on version 4.3.42(5) but when others try to run my code on their 3.x.x version it dosent work.

---------- Post updated at 07:56 PM ---------- Previous update was at 07:54 PM ----------

Thank you. I'll download 3.2.57(1) version and change my code accordingly..

Looks like 4.x.x(which i use) has some array and keyboard input options which dosent work on 3.x.x so i'll have to modify my code.

The 'read' statement will more than likely be your Achilles Heel...
read -r -n 1 -s -t .025 key
You can't use a floating point time out timer on the pre-version 4.x.x read statement.
If you use -t 0 for your whole number timer then the keystroke does NOT get put into the 'key' variable. It does get sent to 'stdout' but that is useless.
So the minimum value for your game to work is '-t 1' which is 1 second.

I don't think there is a workaround using inkey() { char="" ; stty -icanon min 0 time 1 ; char=$( dd count=1 2> /dev/null ) ; } either.
(Thanks to Corona688 for showing me this method a few years back.)

Ohh ok. 1 second is too slow for the game i have made. I tried several options and 0.25 is optimum for reading the input from keyboard .With 1 second as time out the snake wont turn in time and will get caught. If possible ,please try downloading version 4.3.42(5) and running the code in it if you have free time.