Created
December 12, 2022 01:03
-
-
Save mokanfar/ed1b00f5f8c36edcdfdaa719b8fec848 to your computer and use it in GitHub Desktop.
Extract newly downloaded Most Common Archived files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This function takes a file name as input | |
# and performs extraction based on the file type | |
function file_actions { | |
# Set the file name as a static variable | |
file_name=$1 | |
# Check the file name | |
if [[ $file_name == *.zip ]]; then | |
# If the file name ends with .zip, perform custom function "A" | |
# Unzip the zip file and send the output to /dev/null | |
unzip $file_name -d "${file_name%.*}" > /dev/null | |
elif [[ $file_name == *.tar.gz ]]; then | |
# If the file name ends with .tar.gz, perform custom function "B" | |
# Extract the tar.gz file and send the output to /dev/null | |
tar -xzf $file_name -C "${file_name%.*}" > /dev/null | |
elif [[ $file_name == *.tar.bz ]]; then | |
# If the file name ends with .tar.bz, extract the tar.bz file and send the output to /dev/null | |
tar -xjf $file_name -C "${file_name%.*}" > /dev/null | |
elif [[ $file_name == *.rar ]]; then | |
# If the file name ends with .rar, extract the rar file and send the output to /dev/null | |
unrar e $file_name "${file_name%.*}" > /dev/null | |
else | |
# If the file name does not match any of the above conditions, print an error message | |
echo "Error: unrecognized file type" | |
fi | |
} | |
# Get the latest absolute file using another helper script | |
file_name=$(./most_recent_file.sh -e) | |
# Call the file_actions function with the latest file name as an argument | |
file_actions $file_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment