Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Nested If-Else Error

I'm trying to get my bash profile to activate a kerl instance on shell startup, so I put the following in my .profile:

if [ -d /opt/erlang/ ]; then 
    ERL_ENV=`ls -1d /opt/erlang/r* | sort | tail -1`;

    if [ -f "$ERL_ENV/activate" ]; then
        . $ERL_ENV/activate 
    else
        echo "Couldn't activate latest erlang environment"
    fi
fi

When I try to source the file though I get this error:

-bash: .profile: line 30: syntax error near unexpected token `then'
-bash: .profile: line 30: `    if [ -f "$ERL_ENV/activate" ]; then'

I've tried it a few ways but my bash is too rusty. What's the problem?

I'm using Bash on OSX.(GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12))

like image 220
Alex Moore Avatar asked Jan 27 '26 11:01

Alex Moore


1 Answers

I decided to turn on HARD MODE and look at the hex. Ended up being a unicode character that was copy-pasted in.

The hex for the file looks like this: Free Hexy Pics!

The "e2 8082" where the cursor is located in the picture is actually a silly little En Space.
Replacing those with real spaces fixed it.

Thanks for everybody else's answers though!

like image 99
Alex Moore Avatar answered Jan 30 '26 10:01

Alex Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!