Emad
Emad

Reputation: 43

comparing two strings with "-" hyphen in bash

I'm trying to compare two strings that contain "-" in them , for example:

if [[ "–change_team" == "${Args[2]}" ]]; then

where "${Args[2]}" is "–change_team"

I tried to print "–change_team" like this :

echo "–change_team"

and I got is :

âchange_team

the if statement never gives success , and I've tried escaping with "" it didn't go well for me.

Upvotes: 3

Views: 1960

Answers (1)

lurker
lurker

Reputation: 58284

There are a few different 8-bit graphic characters that may look like a hyphen depending upon the character being used for the user interface. In the case of your if statement:

if [[ "–change_team" == "${Args[2]}" ]]; then

If I copy your "–change_team" string and use it here:

echo "–change_team" | od -c

I get this result:

0000000 342 200 223   c   h   a   n   g   e   _   t   e   a   m  \n
0000017

If it were a real hyphen, you'd get:

0000000 -   c   h   a   n   g   e   _   t   e   a   m  \n
0000017

So in the original script, the "hyphen" character being used in the comparison isn't a proper hyphen.

Upvotes: 2

Related Questions