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
@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:~$ 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.
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””
@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
Hey Narcosis,
No I never figured it out.
I finally ditched Debian and Arch is my workhorse now.
Decided to do the script in python instead and have not looked back.
I do maintain bash aliases and a few simple command scripts and am slowly moving over to oh-my-zsh as my shell. It has a lot of nice features for git and themes.