Skip to content

Instantly share code, notes, and snippets.

@osmangoninahid
Created June 5, 2017 18:34
Show Gist options
  • Save osmangoninahid/6bd7a6f9eb2ccd571317f88da27496e6 to your computer and use it in GitHub Desktop.
Save osmangoninahid/6bd7a6f9eb2ccd571317f88da27496e6 to your computer and use it in GitHub Desktop.
Archive creator bash script for *nix
#!/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