Вот один прием, который вы увидите в разных местах:
status=`ps -efww | grep -w "[a]bc.sh" | awk -vpid=$ '$2 != pid { print $2 }'`
if [ ! -z "$status" ]; then
echo "[`date`] : abc.sh : Process is already running"
exit 1;
fi
Скобки вокруг [a]
(или выберите другую букву) не позволяют grep
найти себя. Это делает бит grep -v grep
ненужным. Я также удалил grep -v $
и исправил часть awk
, чтобы выполнить то же самое.
Swift 5
extension UIView {
var cgImage: CGImage? {
guard bounds.size.width > 0 && bounds.size.height > 0 else {return nil}
UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, contentScaleFactor)
layer.render(in: UIGraphicsGetCurrentContext()!)
defer {UIGraphicsEndImageContext()}
return UIGraphicsGetImageFromCurrentImageContext()!.cgImage!
}
}