0

I have the following script, which takes in a sentence from a user and then prompts the user whether they want it in all caps or lower case and echos that output, however the script is not working as I am facing the following error:

./casechanger.sh 
Enter in your sentence, word or phrase: hello
Enter 1 to change the case to UPPER or 2 to change the case to LOWER: 1
./casechanger.sh: line 12: [1: command not found
./casechanger.sh: line 16: [1: command not found
Please select either 1 for upper or 2 for lower.

Here is my code:

read -p "Enter in your sentence, word or phrase: " WORD
read -p "Enter 1 to change the case to UPPER or 2 to change the case to LOWER: " CASE

if ["$CASE" == "1"]
then
        echo $(cat "$WORD" | tr [:lower:] [:upper:])

elif ["$CASE" == "0"]
then
        echo $(cat "$WORD" | tr [:upper:] [:lower:])

else
        echo "Please select either "1" for upper or "2" for lower."
fi

I have tried multiple things including changing "$CASE" == "1" to "$CASE" -eq "1" etc.

Armaan
  • 75
  • 1
  • 7
  • 2
    Paste your script into [ShellCheck](https://www.shellcheck.net/). – JRFerguson Nov 28 '21 at 20:00
  • 2
    you have to say "echo", not "cat". Cat outputs a file, and there probably is no file called $WORD – Thorsten Staerk Nov 28 '21 at 20:03
  • `["$CASE" == "1"]` would expand to something like i.e. `[1 == 1]`, which means that you want to execute a command named `[1` with parameters `==` and `1]`. Since you don't have a command of this name, you get the error message. Since you are using bash, you could write `if ((CASE==1))` instead. `((....))` is a syntactic construct for integer operation, and bash would not try to find an executable file of this name, but do the comparision. – user1934428 Nov 29 '21 at 12:39

0 Answers0