0

This is the BASH script:

#!/bin/bash

read -p "Type in a color name, please: " COLOR

case "$COLOR" in green | red | yellow) echo -n "nice colors!" ;; *) echo -n "meh..." ;; esac

Once set the x permission to the script for user, I run it but get the following:

[inewton@centos7 LPIC1-exercises]$ ./colors.sh
Type in a color name, please: pink
./colors.sh: line 12: syntax error near unexpected token `newline'
'/colors.sh: line 12: `esac
[inewton@centos7 LPIC1-exercises]$

What am I doing wrong? Help me please.

1 Answers1

5
'/colors.sh: line 12: `esac

Notice the weird placement of the closing quote at the beginning of the line. That's a sign that there was a carriage return (CR) character after the word esac. Bash treats the CR as part of the word esac␍, so this is not a reserved word, and the actual word esac is missing.

CR characters are part of Windows line endings: a Unix line ending is the LF (line feed) character alone, whereas a Windows line ending is the two-character sequence CR+LF. See #!/bin/bash - no such file or directory for more explanations. The twist here is that your file has mixed line endings: previous lines didn't cause a problem so at least some of them must have Unix line endings.

Remove all carriage returns from your file. Most editors will show them explicitly in a file with mixed line endings.