19,610
社区成员
发帖
与我相关
我的任务
分享
test 1=2;echo $?
。
test返回的状态码:
0 if the expression is true,
1 if the expression is false,
2 if an error occurred.
再解释下为什么要看test的状态码?
if 后跟的就是test条件 见:http://ss64.com/bash/if.html
test帮助手册: man test; 详细文档:info coreutils 'test invocation'
另外关于比较运算符= 可以看 man expr; 详细文档: info coreutils 'expr invocation'
=有两个上下文,一个赋值,一个比较运算符,不同的上下文有区别,不要混淆了[/quote] 前段时间简单学习了下Shell,最近又做Java开发了, 共同学习 test 1=2;echo $?
。
test返回的状态码:
0 if the expression is true,
1 if the expression is false,
2 if an error occurred.
再解释下为什么要看test的状态码?
if 后跟的就是test条件 见:http://ss64.com/bash/if.html
test帮助手册: man test; 详细文档:info coreutils 'test invocation'
另外关于比较运算符= 可以看 man expr; 详细文档: info coreutils 'expr invocation'
=有两个上下文,一个赋值,一个比较运算符,不同的上下文有区别,不要混淆了[/quote] 前段时间简单学习了下Shell,最近又做Java开发了, 共同学习 [/quote]
bash到java跨度不小test 1=2;echo $?
。
test返回的状态码:
0 if the expression is true,
1 if the expression is false,
2 if an error occurred.
再解释下为什么要看test的状态码?
if 后跟的就是test条件 见:http://ss64.com/bash/if.html
test帮助手册: man test; 详细文档:info coreutils 'test invocation'
另外关于比较运算符= 可以看 man expr; 详细文档: info coreutils 'expr invocation'
=有两个上下文,一个赋值,一个比较运算符,不同的上下文有区别,不要混淆了
weblogic@z174774C6c16g120gs11-1:~/Oracle/Middleware/app_packages> cat test.sh
a=2
if [ $a -eq 2 ];then
para="nihao"
else
para="haha"
fi
echo $para
weblogic@z174774C6c16g120gs11-1:~/Oracle/Middleware/app_packages> sh test.sh
nihao
weblogic@z174774C6c16g120gs11-1:~/Oracle/Middleware/app_packages>
可以直接赋值,=前后不能有空格#!/bin/bash
a=2
para=
if [ $a == 1 ];then
echo para = $para
else
para=-Dlog.file=/file.log
echo para = $para
fi
/usr/java $para