简体   繁体   English

“在Mac OSX(ML)的zsh上预期的条件:<”

[英]“condition expected: <” on zsh in Mac OSX(ML)

I'm learning shell scripts on the zsh on Mac OSX(ML). 我正在Mac OSX(ML)上学习zsh上的shell脚本。

When tring 什么时候

test good \< bad

it gives 它给

zsh: condition expected: <

Can anyone explain this? 有谁能解释一下?

Can you not just use flags to test? 你能不能只用旗帜来测试?

% test 1 -lt 2 && echo 'it\'s less! yay!'
% test 1 -gt 2 && echo 'ohnoes, math is broken'

Incidentally, using your test here, 'test 1 \\< 2' works in bash and fails in zsh . 顺便说一句,在这里使用你的测试,'test 1 \\ <2'在bash工作,在zsh失败。 Looking at the zsh docs ( zshbuiltin among others), it seems that < is in fact the right operator for less than, but go ahead and use the -lt and -gt . 看看zsh文档( zshbuiltin等),似乎<实际上是小于的运算符,但是继续使用-lt-gt If you must use the left angle bracket, use this syntax: 如果必须使用左尖括号,请使用以下语法:

% [[ 1 < 2 ]] && echo 'hooray for angle brackets!'

which seems to work on my zsh, which is zsh 4.3.11 (i386-apple-darwin12.0) . 这似乎适用于我的zsh,这是zsh 4.3.11 (i386-apple-darwin12.0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM