Error checking in script

The error checking does not work in this case.

The directory does not exist, but cp assumes that Ubuntu_Mate_18.0 is the name of the file.

Any way to correct that?

 cp -u -f Ubuntu_Documents.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.0
 if [ "$?" != "0" ]; then 
gxmessage -fg red -font  'sans 50' -timeout 3 -geometry 1600x200 ' COPY Failed !!'
 #   echo "[Error] copy failed!" 1>&2
   exit 1
 fi

if [ $? -ne 0 ]; then

It is not working.

cd ~/Documents
cp -u -f Ubuntu_Documents.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.0
if [ $? -ne 0 ]; then
gxmessage -fg red -font ‘sans 50’ -timeout 3 -geometry 1600x200 ’ COPY Failed !!’
# echo “[Error] copy failed!” 1>&2
exit 1
fi

if ! cp -u -f Documents.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.0/ 2>/dev/null
then
     gxmessage -fg red -font 'sans 50' -timeout 3 -geometry 1600x200 ' COPY Failed !!'
     # echo "[Error] copy failed!" 1>&2
     exit 1
fi

IMHO the trailing slash is missing at the end of the path …Ubuntu_Mate_18.0/

Kr

I know that. I frequently edit that script.

I thought that if I made a mistake in the path, there would be a way to catch the error.

myfolder="/media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.0"

if [[ ! -d "${myfolder}" ]]; then
   echo "folder does not exists"
  exit 1
elif ! cp -u -f Documents.zip "${myfolder}/" 2>/dev/null
then
     gxmessage -fg red -font 'sans 50' -timeout 3 -geometry 1600x200 ' COPY Failed !!'
     # echo "[Error] copy failed!" 1>&2
     exit 1
fi