Shell可以运行命令,但ZSH不能

时间:2018-01-15 11:32:32

标签: bash zsh

如果我使用Bash并运行. ./setantenv.sh,我的项目文件夹中就可以了。

但是在同一个文件夹中,如果我使用ZSH并尝试运行. ./setantenv.sh,则会产生./setantenv.sh:4: = not found

ZSH在运行所有其他命令时没有任何问题。但它似乎无法识别.

之前的第一个./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 

任何帮助?

2 个答案:

答案 0 :(得分:1)

<a href="http://example.com" tabindex="3">Link</a> <input type="text" tabindex="2"> <select tabindex="5"> <option>Option A</option> <option>Option B</option> <option>Option C</option> </select> <textarea tabindex="4">Hello world</textarea> <button tabindex="1" id="Btn">Button</button> <button tabindex="1" id="BtnRes">restore tabindex</button>

if [ "$0" "==" "./$OWN_NAME" ]; then

运行if [ "$0" = "./$OWN_NAME" ]; then

重写如此。

答案 1 :(得分:1)

thistest及其别名[的最新POSIX规范。如您所见,整个页面中没有==

freebsd test(1)手册页说:

COMPATIBILITY
     For compatibility with some other implementations, the = primary
     can be substituted with == with the same meaning.

但是zsh内置[

% 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

...而zsh的版本没有==。来自 zshbuiltins(1)(只有第二个概要行的外括号是实际语法,其余为*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,您收到的错误消息为= not found,因为zsh使用前导=进行文件名扩展。来自 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.

显然,=中的任何地方都没有名为$PATH的命令。 :)

% echo =ls
/bin/ls
% echo =fubar
zsh: fubar not found
% echo ==
zsh: = not found
相关问题