Skip to content

Instantly share code, notes, and snippets.

@lyuboraykov
Created August 21, 2014 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyuboraykov/5701b39be46e4d7b5a0e to your computer and use it in GitHub Desktop.
Save lyuboraykov/5701b39be46e4d7b5a0e to your computer and use it in GitHub Desktop.
Try-catch file copying in bash
#!/usr/bin/env bash
{
#try block
cp non/existing/file non/existing/folder
} || {
#catch block
if [ $? != 0 ]; then
echo "File copying failed."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment