我在bash脚本中有一个函数,如果进程正在运行,我想返回true,否则返回false。我的功能代码是:
checkProcess() {
if [ kill -s 0 $(getPid) > /dev/null 2>&1 ]; then
return 0
else
return 1
fi
}
当我使用此功能时,它似乎不起作用。我这样使用它:
if [ ! checkProcess ]; then
#do something, like rm file containing PID
fi
但是,如果我只是使用以下实现,它可以正常工作:
if [ ! kill -s 0 $(getPid) > /dev/null 2>&1 ]; then
#do something, like rm file containing PID
fi
这有什么理由吗?我没有在函数中返回正确的值吗?还是只是错误地实施了?
答案 0 :(得分:8)
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='-11' BindingExpression:Path=ActualWidth; DataItem='ContentPresenter' (Name=''); target element is 'TextBlock' (Name=''); target property is 'Width' (type 'Double')
不是语法;这是一个命令。它通常与[
一起使用,它基于其返回码工作。
直接检查不同命令的返回码,例如if
,您应该移除kill
和[
(]
的最后一个参数):
[