If your actual shell is /bin/sh
[contrary to the initial question, but as discussion commentary has made clear], use =
rather than ==
in your test expression:
elif [ "$basePath" = arrayscripts ]
Note that the right-hand side doesn't need to be quoted in this case, since it contains no expansions and no syntactically-sensitive characters.
Alternately, if this issue is reproducible when using bash, the obvious problem is missing quotes.
Use either
[ "$basePath" = arrayscripts ] # this is POSIX compatible
or
[[ $basePath = arrayscripts ]] # this works only with bash
Otherwise, the number of arguments $basePath
expands into is undefined -- it may expand into zero arguments, making the statement
[ = arrayscripts ]
...which would try to use =
as a unary operator, which it isn't...
or if $basePath
contained, say, "true -o bar ="
, it could expand into something like
[ true -o bar = arrayscripts ]
...resulting in program behavior very different from what you actually want.
Bottom line: When writing for shells which follow POSIX rules (basically, anything but zsh or fish), quote your expansions unless you have a specific and compelling reason to do otherwise. (Use of the bash/ksh extension [[ ]]
provides such a reason, by introducing a context in which string-splitting of expansion results and glob expansion don't take place).
dash
(defaultsh
in Ubuntu) which doesn't support==
. See Bashisms"$basePath"
is not the same as$basePath
-- unquoted, the latter can expand to any number of arguments, making what it puts in the operator position completely unpredictable.bash
, are you starting your script with#!/bin/bash
? If not, you should.`pwd`
is considerably less efficient than$PWD
.