-2

Can someone explain how to correctly do an if/else in bash when comparing a parameter to a string? In detail please, I tried to combine elements of these websites 1 2 3 but I don't know what went wrong.

#!/bin/bash
sellx=125
selly=154 #top
itemwidth=10

#takes in two params $1=buy/sell   $2=number in buy or sell
ModifyItem(){
    if [["$1"=="sell"]] 
    then
        xdotool mousemove "$sellx" "$(($selly+$2*$itemwidth))";
    else
        echo "nope";
    fi
}

ModifyItem sell 2 
Community
  • 1
  • 1
Rilcon42
  • 9,584
  • 18
  • 83
  • 167

1 Answers1

1

Whitespace is important; you need to separate the == operator from its arguments, and you need to separate the brackets from the condition.

if [[ "$1" == "sell" ]]
chepner
  • 497,756
  • 71
  • 530
  • 681