Bash Script error in Debian?

Strange!
can’t seem to get an array going?

Running the script:
sh bin/readTest.sh

Debian 12 responds:

*Enter Fullname:  Jeff Pro*
  • Welcome Jeff Pro.*
  • bin/readTest.sh: 6: Syntax error: “(” unexpected*

I am getting getting other errors as well that are right of the man bash.

I have a menu driven script that works fine in Arch but not Debian?

#!/bin/bash

echo -n "Enter Fullname: "
read fullname
echo “Welcome $fullname.”
myArray=(“cat” “dog” “mouse” “frog”)

for str in ${myArray[@]}; do
echo $str
done

for i in ${!myArray[@]}; do
echo “element $i is ${myArray[$i]}”
done

Code works fine, looks fine. I am on PoP 22.04

Which version of Debian? I’ve got a Debian 10 vm which runs it ok.

john@debian:~$ cat /etc/os-release
PRETTY_NAME=“Debian GNU/Linux 10 (buster)”
NAME=“Debian GNU/Linux”
VERSION_ID=“10”
VERSION=“10 (buster)”
VERSION_CODENAME=buster
ID=debian
HOME_URL=“https://www.debian.org/
SUPPORT_URL=“Debian -- User Support
BUG_REPORT_URL=“https://bugs.debian.org/

john@debian:~$ bash test.sh
Enter Fullname: Joe Blow
“Welcome Joe Blow.”
“cat”
“dog”
“mouse”
“frog”
“element 0 is “cat””
“element 1 is “dog””
“element 2 is “mouse””
“element 3 is “frog””

FWIW, which version of bash on your Debian box?

john@debian:~$ bash -version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 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.

@Narcosis @mcron
Debian 12
I put together a tester with a related error:
Was using an array to hold the choices and got the earlier noted error on Deb12.
Keeping it simple this is where I started.
FYI: I use Arch(LTS) to test ideas and Deb(12) is my workhorse.

#!/bin/bash

###################################
##      Bash-Script MENUs        ##
##  Debian 12 (Bookworm) version ##
##  read -options create errors  ##
##    https://forums.jeff.pro/   ##
##     (chmod +x bashMenu.sh)    ##
##    :~$  sh bin/bashMenu.sh    ##
###################################

# Present the user with a MENU choice.
echo "Select:"
echo "        1. Projects"
echo "        2. Documents"
echo "        3. Music"

# Read the Users keyboard response into choice:
read choice;

# The response is now stored as a variable: $choice
# case allows bash to test for these options.
    case $choice in
        1) echo "You chose Projects";;
        2) echo "You chose Documents";;
        3) echo "You chose Music";;
        * ) echo "$choice is NOT available - Try again (1,2, or 3)";;
    esac
exit

try with

read -n 1 choice

-n Returns after reading the specified number of characters.

:~$ sh bin/bashMenu.sh
Select:
1. Projects
2. Documents
3. Music
bin/bashMenu.sh: 18: read: Illegal option -n

Worked fine here, and even the read command is working as intended on the command line. Befuddled I am.

Version of Bash on my system, since I did not send it last time.
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)

@mcron my Debian 12 GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
I think my Arch is 5.1.016-4 minimal, where the scripts work! I was able to reproduce error on the current Zorin in a virtual machine.

Interesting issue. Not critical as it’s just me on my machine.

I do have some bash scripts I want to share with my folk here. So surprised when debian barfed on basic options.

I use neofetch to display my system config but it does NOT show bash version

Your comment about Zorin had me curious so I tested your script successfully in a Zorin 16.3 VM. Might there be something in your $ENV which is somehow getting in the way?

john@zorin-vm:~$ cat /etc/os-release
NAME=“Zorin OS”
VERSION=“16.3”
ID=zorin
ID_LIKE=ubuntu
PRETTY_NAME=“Zorin OS 16.3”
VERSION_ID=“16”
HOME_URL=“Zorin OS - Make your computer better.
SUPPORT_URL=“https://help.zorin.com/
BUG_REPORT_URL=“Send Feedback - Zorin OS
PRIVACY_POLICY_URL=“Privacy Policy - Zorin
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

john@zorin-vm:~$ bash -version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 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.

john@zorin-vm:~$ cat bash-test.sh
#!/bin/bash

echo -n "Enter Fullname: "
read fullname
echo “Welcome $fullname.”
myArray=(“cat” “dog” “mouse” “frog”)

for str in ${myArray[@]}; do
echo $str
done

for i in ${!myArray[@]}; do
echo “element $i is ${myArray[$i]}”
done

john@zorin-vm:~$ ./bash-test.sh
Enter Fullname: Joe Blow
“Welcome Joe Blow.”
“cat”
“dog”
“mouse”
“frog”
“element 0 is “cat””
“element 1 is “dog””
“element 2 is “mouse””
“element 3 is “frog””

john@zorin-vm:~$

1 Like
@Narcosis Thanks for looking at this.
 I'll check the $ENV

I'm getting to know bash. Very interesting to learn how it works with aliases and custom prompts.

I'm sure I'll figure it out and will post what I find.
update_1;
OS: Arch Linux x86_64 
Kernel: 6.1.56-1-lts 
Shell: bash 5.1.16 
bare metal
---------
OS: Debian GNU/Linux 12 (bookworm) x86_64 
Kernel: 6.1.0-13-amd64
Shell: bash 5.2.15
bare metal
---------
OS: Zorin OS 16.3 x86_64  (lite version)
Kernel: 5.15.0-84-generic 
Shell: bash 5.0.17 
GPU: 00:01.0 Red Hat, Inc. Virtio GP