dimanche 27 septembre 2020

Why is "if [ -z "ls -l /non_existing_file 2> /dev/null" ] not true [duplicate]

I want to check if an external drive is still plugged in by checking /dev/disk/by-uuid/1234-5678.

However, I know that this could be done much easier with:

if ! [ -e "/non_existing_file" ]
   echo "File dont exists anymore"
fi

But I still want to know why the script in the Title dont work. Is it because of the exit code of ls?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire