Why am i getting an unexpected operator error in bash string equality test?

bash

Solution

You can't use == for single bracket comparisons ([ ]). Use single = instead. Also you must quote the variables to prevent expansion.

if [ "$bn" = README ]; then

If you use [[ ]], that could apply and you wouldn't need to quote the first argument:

if [[ $bn == README ]]; then

Problem

Where is the error on line four? ``` if [ $bn == README ]; then ``` which i still get if i write it as ``` if [ $bn == README ] then ``` or ``` if [ "$bn" == "README" ]; then ``` Context: ``` for fi in /etc/uwsgi/apps-available/* do bn=`basename $fi .ini` if [ $bn == "README" ] then echo "~ ***#*** ~" else echo "## Shortend for convience ##" fi done ```

Original source

Related problems