read -p "Enter yes/no " SOMEVAR
SOMEVAR=`"echo ${SOMEVAR,,}"`
The code above gives me a ${SOMEVAR,,}: bad substitution error.
read -p "Enter yes/no " SOMEVAR
SOMEVAR=`"echo ${SOMEVAR,,}"`
The code above gives me a ${SOMEVAR,,}: bad substitution error.
The parameter expansion ${variable,,} would expand to the value of $variable with all character in lower case in the bash shell. Given that you get a "bad substitution" error when this code runs suggests that you are in fact either
/bin/sh (which is not always bash). But not getting an error for read -p suggests that it's more likely that you arebash which does not support this expansion (introduced in release 4 of bash).The generic form of the expansion is ${variable,,pattern} in which all characters in $variable that matches pattern would be converted to lower case (use ^^ to convert to upper case):
$ str="HELLO"
$ printf '%s\n' "${str,,[HEO]}"
heLLo
See also the bash manual on your system.
For older releases of bash, you could instead do the following to lowercase the value of a variable:
variable=$( tr 'A-Z' 'a-z' <<<"$variable" )
This passes the value of the variable through tr using a "here-string". The tr utility transliterates all characters in the A to Z ASCII range (assuming the C/POSIX locale) to the corresponding character in the a to z range.
Note also that
SOMEVAR=`"echo ${SOMEVAR,,}"`
is better written as
SOMEVAR=${SOMEVAR,,}
In fact, what you wrote would give you a "command not found" error in bash release 4+, unless you have a command called echo string, including the space (where string was what the user inputted). This is due to the command substitution trying to execute the double quoted string.
bashinstalled in/bin/bash. To fix that, try installing a newerbashusing Homebrew (if you're on macOS) and then run the script with thatbashas/usr/local/bin/bash installscript(or whatever the script is called), or change the#!-line to point to the newerbash. – Kusalananda Feb 12 '19 at 21:07/bin/bashbinary with a newer version. – Kusalananda Feb 13 '19 at 08:54bashis updated past release 4 (the latest is release 5.0), it is guaranteed to work. Well, the${variable,,}thing will work anyway. Also note that an Ubuntu installation running abashthat is that old is uncommon (it must be older than Ubuntu 14, which has reached its end of life now), and I would seriously question the sysadmin's dedication to keeping the system up to date and secure. – Kusalananda Feb 13 '19 at 17:38bashinstalled on it would likely be a security risk in itself. – Kusalananda Feb 13 '19 at 18:03`while [[ $SOMEVAR = "" ]] ; do
This is how the erroneous part of the script is.
– Hitanshu Sachania Feb 20 '19 at 19:09echoshould not be there. See the second part of my answer. Do you still get a "bad substitution" error? – Kusalananda Feb 20 '19 at 19:18