0

I have the simplest issue, but I can't get this to work, and it's driving me crazy. So I am running a script called execute.sh that has a help function. I swear my syntax is correct below; I have tried just one equal sign and now trying two. I have tried the double brackets and continue to get the error "[-h: command not found" . To execute the script I run the following the command.

sh execute.sh -h

Where -h is the argument I am passing int that forces the bash script to call the help function and then exist. But it keeps erroring on the IF Statement. Not sure what else to do, any suggestions?

arg=$1

if ["$arg" == "-h"]; then
    helpFunction
    exit1;
fi
Cyrus
  • 84,225
  • 14
  • 89
  • 153
Maxamis4
  • 137
  • 8
  • 1
    Additionally, it has to be `exit 1`, not `exit1`. https://www.shellcheck.net/ can point out things like that for you. – Benjamin W. Nov 26 '22 at 18:47

1 Answers1

1

In

["$arg" == "-h"]

line, you should separate the [ from " also " from the ] with a space. Because [ is actually a command, so it should have a space after it, and the syntax of [ command arguments require a space before ].

arg=$1

if [ "$arg" == "-h" ]; then
    helpFunction
    exit 1;
fi