我在.bash_profile
中有这个功能function suman {
LOCAL_SUMAN=$(node $HOME/.suman/find-local-suman-executable.js);
if [ -z "$LOCAL_SUMAN" ]; then
echo "No local Suman executable could be found, given the current directory => $PWD"
return 1;
else
return node "$LOCAL_SUMAN" "$@"; # this is wrong I think
fi
}
我只想返回节点进程的退出代码,但我认为上面的行不正确,从suman函数返回正确退出代码的正确方法是什么?
我猜想退出代码会被同一行上的节点进程“返回”。
也许我应该删除return关键字?
答案 0 :(得分:1)
在该行中您不需要node "$LOCAL_SUMAN" "$@"
;只需致电node
;由于它是您的函数执行的最后一个命令,因此您的函数将以与调用suman () {
LOCAL_SUMAN=$(node $HOME/.suman/find-local-suman-executable.js)
if [ -z "$LOCAL_SUMAN" ]; then
echo "No local Suman executable could be found, given the current directory => $PWD"
return 1
else
node "$LOCAL_SUMAN" "$@"
fi
}
相同的返回状态退出。
List<T> oldList = new List<T> { Soc1, Soc2, Soc3 };
List<T> newList = new List<T> { Soc1, Soc3, Soc4 };
int i = 0;
// Go trough the old list to remove items which don't exist anymore
while(i < oldList.Count)
{
// If the new list doesn't contain the old element, remove it from the old list
if (!newList.Contains(oldList[i]))
{
oldList.RemoveAt(i);
}
// Otherwise move on
else
{
i++;
}
}
// Now go trough the new list and add all elements to the old list which are new
foreach(T k in newList)
{
if (!oldList.Contains(k))
{
oldList.Add(k);
}
}