0

I am learning how to use bash and I ran into a bad substitution error with the following code

#!/bin/bash

if [ ${1,,} = herbert ]; then
    echo "Oh, you're the boss here. Welcome!"
elif [ ${1,,} = help ]; then
    echo "Just enter your username, duh!"
else
    echo "I don't know who you are. But you're not the boss of me!"
fi

the line highlighted to be responsible for this is line 3: ${1,,}. How do I resolve this?

Tito Lulu
  • 85
  • 6
  • What substitution are you trying to achieve? – Matthieu Apr 12 '23 at 13:29
  • 2
    Edit your question and tell us what you expect that `${1,,}` is supposed to do. OR you can copy/paste all of your code into https://shellcheck.net and fix any errors flagged and see if that solves your problem. Good luck. – shellter Apr 12 '23 at 13:30
  • 1
    Which version of BASH? – Dima Chubarov Apr 12 '23 at 13:30
  • Are you actually using Bash? – Andrej Podzimek Apr 12 '23 at 13:31
  • 3
    the line is fully legal, so it should work. Maybe you have a very ancient bash version, or some fake bash, not implementing all substitution options? off topic: you should surround the variables with double quotes to avoid syntax errors when variable is empty. – Synopsis Apr 12 '23 at 13:32
  • 3
    The `${parameter,,}` expansion was introduced with version 4.0 of Bash. It won't work if your Bash version is older, or your shell isn't Bash. As an aside, you should quote the expansion: `"${1,,}"` – M. Nejat Aydin Apr 12 '23 at 13:36
  • This very much looks like you're running too old of a release. – Charles Duffy Apr 12 '23 at 13:39
  • I am using version 3.2 let me try upgrading and run the code again – Tito Lulu Apr 12 '23 at 13:39
  • I linked to a question about how to compare strings in a case-insensitive way, because that's what the code you're trying/failing to run is for. As others have said, the reason it doesn't work is that bash 3.2 is too old to support this syntax; the duplicate has answers that describe this version constraint and have alternatives that aren't tied to it. – Charles Duffy Apr 12 '23 at 13:42
  • The issue was with the bash version. Upgrading it resolved my issue. Thanks – Tito Lulu Apr 12 '23 at 13:55

0 Answers0