Reputation: 6675
Inside my project folder if I use Bash and run . ./setantenv.sh
, it works.
But in the same folder if I use ZSH and try to run . ./setantenv.sh
, it results in ./setantenv.sh:4: = not found
ZSH doesn't have any issues to run all the other commands. But it seems that it doesn't recognise the first .
before the ./AnyCommand.sh
#!/bin/bash
OWN_NAME=setantenv.sh
if [ "$0" == "./$OWN_NAME" ]; then
echo * Please call as ". ./$OWN_NAME", not ./$OWN_NAME !!!---
echo * Also please DO NOT set back the executable attribute
echo * On this file. It was cleared on purpose.
chmod -x ./$OWN_NAME
exit
fi
PLATFORM_HOME=`pwd`
export -p PLATFORM_HOME
export -p ANT_OPTS="-Xmx400m -XX:MaxPermSize=128M"
export -p ANT_HOME=$PLATFORM_HOME/apache-ant-1.9.1
chmod +x "$ANT_HOME/bin/ant"
export -p PATH=$ANT_HOME/bin:$PATH
echo Setting ant home to: $ANT_HOME
ant -version
Any help?
Upvotes: 1
Views: 1508
Reputation: 19237
this is the latest POSIX specification for test
and its alias, [
. as you can see, there's no ==
in the whole page.
freebsd test(1) man page says:
COMPATIBILITY
For compatibility with some other implementations, the = primary
can be substituted with == with the same meaning.
but zsh has [
builtin:
% for sh in sh bash mksh zsh; do $sh -c "printf '%-5s- ' $sh; which '['"; done
sh - /bin/[
bash - /bin/[
mksh - /bin/[
zsh - [: shell built-in command
... and zsh's version does not do ==
. from zshbuiltins(1) (only the outer brackets on the second synopsis line are actual syntax, the rest is *BNF):
test [ arg ... ]
[ [ arg ... ] ]
Like the system version of test. Added for compatibility; use
conditional expressions instead (see the section `Conditional
Expressions'). The main differences between the conditional
expression syntax and the test and [ builtins are: these
commands are not handled syntactically, so for example an empty
variable expansion may cause an argument to be omitted; syntax
errors cause status 2 to be returned instead of a shell error;
and arithmetic operators expect integer arguments rather than
arithmetic expressions.
The command attempts to implement POSIX and its extensions where
these are specified. Unfortunately there are intrinsic
ambiguities in the syntax; in particular there is no distinction
between test operators and strings that resemble them. The
standard attempts to resolve these for small numbers of
arguments (up to four); for five or more arguments compatibility
cannot be relied on. Users are urged wherever possible to use
the `[[' test syntax which does not have these ambiguities.
btw, the error message you got says = not found
because zsh uses leading =
for filename expansion. from zshexpn(1):
'=' expansion
If a word begins with an unquoted '=' and the EQUALS option is set, the
remainder of the word is taken as the name of a command. If a command
exists by that name, the word is replaced by the full pathname of the
command.
apparently, there's no command named =
anywhere in your $PATH
. :)
% echo =ls
/bin/ls
% echo =fubar
zsh: fubar not found
% echo ==
zsh: = not found
Upvotes: 2
Reputation: 1838
if [ "$0" "==" "./$OWN_NAME" ]; then
or
if [ "$0" = "./$OWN_NAME" ]; then
rewrite like this when runs zsh
.
Upvotes: 2