shell编程的一个问题
发表于 : 2007-06-12 15:53
#!/bin/sh
if cp test test1
then echo“cp done”
else echo “cp fail”
fi
cp 成功不是返回0 吗?
为什么这个if 后执行的是1?
if cp test test1
then echo“cp done”
else echo “cp fail”
fi
cp 成功不是返回0 吗?
为什么这个if 后执行的是1?
完全没有问题$echo test >test
$cp test test1
$echo $?
0
$rm test
$cp test test1
cp: 无法确认 ‘test’: No such file or directory
$echo $?
1
也没有问题$echo '#!/bin/sh
if cp test test1
then echo "cp done"
else echo "cp fail"
fi' >test.sh
$echo test >test
$sh test.sh
cp done
$rm test
$sh test.sh
cp: 无法确认 ‘test’: No such file or directory
cp fail