w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
how to avoid command errors in shell script execution

You can change the middle part of your script like this:

if ! mkdir /tmp/aisync.lock 2>/dev/null; then
  printf "Failed to aquire lock.
" >&2
  exit 1
fi

That way the error message from mkdir will be thrown away. At the same time the behavior is unchanged, mkdir still fails, so the condition in the if will evaluate true and the script will exit with 1.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.