Skip to content

Instantly share code, notes, and snippets.

@kvpb
Last active July 28, 2022 11:14
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 kvpb/b073d4af26e57be942656749399467e4 to your computer and use it in GitHub Desktop.
Save kvpb/b073d4af26e57be942656749399467e4 to your computer and use it in GitHub Desktop.
Test Script 72: delete directory from user home
#!/usr/bin/env bash
if [ -d "${symbolic_link_or_directory}" ]; # If symbolic_link_or_directory exists...
then
if [ -L "${symbolic_link_or_directory}" ]; # If symbolic_link_or_directory is a symbolic link...
then
rm "${symbolic_link_or_directory}"; # Remove symbolic_link_or_directory.
else # Else, i.e. if symbolic_link_or_directory is a directory...
if [ $(ls -A "${symbolic_link_or_directory}") ]; # If symbolic_link_or_directory is empty...
then
mv "${symbolic_link_or_directory}/*" ${HOME}/Desktop/; # Move the contents of symbolic_link_or_directory to the current user's desktop.
rmdir "${symbolic_link_or_directory}"; # Remove symbolic_link_or_directory.
else # Else, i.e. if symbolic_link_or_directory is not empty...
rmdir "${symbolic_link_or_directory}"; # Remove symbolic_link_or_directory.
fi;
fi;
fi;
if [ ! -d "${symbolic_link_or_directory}" ]; # If symbolic_link_or_directory does not exist...
then
exit; # Exit.
fi;
# script72.sh
# Test Script 72: delete directory from user home
#
# Author: Karl V. P. Bertin `kvpb`
# Telephone: +33 A BB BB BB BB
# Email: local-part@domain
# LinkedIn: https://www.linkedin.com/in/karlbertin
# Facebook: https://www.facebook.com/profile.php?id=
# Instagram: https://www.instagram.com/karlbertin/
# Snapchat: https://www.snapchat.com/add/karlbertin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment