Created
June 5, 2017 18:34
-
-
Save osmangoninahid/6bd7a6f9eb2ccd571317f88da27496e6 to your computer and use it in GitHub Desktop.
Archive creator bash script for *nix
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 | |
#variables are declared here | |
param_help="-h" | |
param_version="-v" | |
archieve_creator() { | |
#checks if there is any directory in the parameter | |
if [[ -d "$1" ]]; then | |
echo "This directory exits" | |
tar -czf $(basename $1).tar.gz $1 | |
#checks if parameter is help query | |
elif [[ "$1" == "$param_help" ]]; then | |
echo "This is help query" | |
tar --help | |
#checks if parameter is version query | |
elif [[ "$1" == "$param_version" ]]; then | |
echo "Tar version is $(tar --version | grep -o '[0-9]\.[0-9]')" | |
#checks if there is no parameter at all | |
elif [[ "$1" == "" ]]; then | |
echo "Error!!" | |
fi | |
} | |
#test cases are declared below with differnet paramter passing to the function | |
archieve_creator | |
archieve_creator -v | |
archieve_creator -h | |
archieve_creator Users/osman/Desktop/test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment