Using AudioScope.sh on Ubuntu 17.04 from a live DVD disc I came across an error.
Consider the code below it is a MUCH shortened version of the KEYBOARD input in AudioScope.
#!/bin/bash
bash --version
uname -a
status=0
KEYBOARD()
{
read -r -p "Enter QUIT or EXIT to quit:- " kbinput
if [ "$kbinput" == "QUIT" ] || [ "$kbinput" == "EXIT" ]
then
status=255
break
fi
if [ "$kbinput" == "TEST" ]
then
echo "Hello World!"
fi
}
while true
do
echo "This will loop and hold until keyboard input is quitted."
KEYBOARD
done
echo "you are here..."
When run in OSX 10.12.5 this is the expected result:-
Last login: Wed May 24 16:37:36 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./kb_loop.sh
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.
Darwin Barrys-MBP 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
This will loop and hold until keyboard input is quitted.
Enter QUIT or EXIT to quit:- TEST
Hello World!
This will loop and hold until keyboard input is quitted.
Enter QUIT or EXIT to quit:- QUIT
you are here...
AMIGA:amiga~/Desktop/Code/Shell> _
When run in Linux Mint 18 I get the same expected result from a LIVE DVD:-
mint@mint ~ $ chmod 755 kb_loop.sh
mint@mint ~ $ ./kb_loop.sh
GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Linux mint 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
This will loop and hold until keyboard input is quitted.
Enter QUIT or EXIT to quit:- TEST
Hello World!
This will loop and hold until keyboard input is quitted.
Enter QUIT or EXIT to quit:- QUIT
you are here...
mint@mint ~ $ _
HOWEVER running from a Ubuntu 17.04 current LIVE DVD This is what ensues:-
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
ubuntu@ubuntu:~$ chmod 755 kb_loop.sh
ubuntu@ubuntu:~$ ./kb_loop.sh
GNU bash, version 4.4.5(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Linux ubuntu 4.10.0-19-generic #21-Ubuntu SMP Thu Apr 6 17:04:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
This will loop and hold until keyboard input is quitted.
Enter QUIT or EXIT to quit:- TEST
Hello World!
This will loop and hold until keyboard input is quitted.
Enter QUIT or EXIT to quit:- QUIT
./kb_loop.sh: line 11: break: only meaningful in a `for', `while', or `until' loop
This will loop and hold until keyboard input is quitted.
Enter QUIT or EXIT to quit:- _
NOTE the error:-
./kb_loop.sh: line 11: break: only meaningful in a `for', `while', or `until' loop
And it keeps looping with the same error.
Is this a bug in bash 4.4.5, as bash 4.3.42 and presumably earlier is perfectly fine?!
At what point between 4.3.42 and 4.4.5 would this have broken I wonder?
Can anyone else confirm this error please...
TIA.
Barry.