帮小弟我分析一个shell的结果哦

帮小弟我分析一个shell的结果哦

帮我分析一个shell的结果哦
#!/bin/bash –
function mytest(){
echo “arg1 = $1”
if [ $1 = “1” ];then
   return 1;
else
   return 0;
fi
}

echo
echo “mytest 0 = “`mytest 0`;
if mytest 0;then
echo “mytest 0”;
fi
echo “end”;

这个shell运行结果是
mytest 0 = arg1 =0
arg1 =0

mytest 0
end

但是,我觉得,那红色标记部分不应该打印出来呀,为什么 if后,能把 mytest 0给打印出来哦?


0 不是成功么。。。

if不带[]是只测试后面命令运行是否成功,以$?来判断, 而不是测试0和1

因为mytest 0是返回0,if认为成功, mytest 1是返回1,if认为失败

所以
if mytest 0;then
echo “mytest 0”;
fi
能输出mytest0

帮小弟我分析一个shell的结果哦

相关文章:

你感兴趣的文章:

标签云: