├── README.md ├── areyouthere.sh ├── forloop.sh ├── long_opts.sh ├── short_opts.sh └── whileloop.sh /README.md: -------------------------------------------------------------------------------- 1 | # bash_script_templates 2 | Some Templates for Bash Scripting, which will help you in building you own tool or script..! 3 | 4 | # Templates 5 | 6 | `long_opts.sh` - This Script will help you in getting insight on how you can use long options in bash script using the builtin getopts functions. 7 | 8 | `short_opts.sh` - Similar to long_opts script this will help you understand parsing short options using getopts functions. 9 | 10 | # Contribution 11 | 12 | Contributions are most welcome , please do share you exp while making bash where you learn a new function of bash by contributing here its template to use that functions. 13 | 14 | Thank you. 15 | -------------------------------------------------------------------------------- /areyouthere.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Usage of Script: ./areyouthere.sh firstArg secondArg 4 | #example: ./areyouthere.sh google.com googlesub.txt 5 | #By SouravSec 6 | 7 | #function 8 | if [ -z "$1" ] #if firstArg/$1 is not given 9 | then 10 | echo "First Argument is not defined" 11 | echo "Usage : areyouthere.sh " 12 | exit 1 13 | fi 14 | 15 | if [ -z "$2" ] #if seondArg/$1 is not given 16 | then 17 | echo "Second argument is not defined" 18 | echo "Usage : areyouthere.sh " 19 | exit 1 20 | fi 21 | 22 | 23 | #Print You LOGO 24 | logo(){ 25 | figlet AreYouThere 26 | } 27 | 28 | logo 29 | 30 | echo "Gathering Subdomains... " 31 | subfinder -d $1 -o $2 -------------------------------------------------------------------------------- /forloop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Usage of Script: ./forloop.sh count 4 | #example: ./forloop.sh 20 5 | #By Altaf Shaikh 6 | 7 | for (( counter=$1; counter>0; counter-- )) 8 | do 9 | echo -n "$counter " 10 | done 11 | printf "\n" 12 | -------------------------------------------------------------------------------- /long_opts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | logo(){ 4 | 5 | } 6 | 7 | intel(){ 8 | echo -e "Starting to Gather Intel ..!"; 9 | echo -e "passed value $val" 10 | } 11 | 12 | while getopts ":h-:" optchar;do 13 | case "${optchar}" in 14 | -) 15 | case "${OPTARG}" in 16 | ia) 17 | val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1)) 18 | intel; 19 | ;; 20 | *) 21 | if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then 22 | echo "Unknown option --${OPTARG}" >&2 23 | fi 24 | ;; 25 | esac;; 26 | h) 27 | echo "usage: $0 [--ia] " 28 | exit 2 29 | ;; 30 | *) 31 | if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then 32 | echo "Non-option argument: '-${OPTARG}'"; 33 | fi 34 | ;; 35 | esac 36 | done 37 | -------------------------------------------------------------------------------- /short_opts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Print You LOGO 4 | logo(){ 5 | 6 | } 7 | logo 8 | 9 | #Functions 10 | gather_links(){ 11 | echo "gathering Links for $target" | tee links.txt 12 | } 13 | 14 | #Save in Output Folder 15 | output(){ 16 | mkdir -p $dir 17 | mv links.txt $dir/ 18 | } 19 | 20 | while getopts ":l:o:" opt;do 21 | case ${opt} in 22 | l ) target=$OPTARG 23 | gather_links 24 | ;; 25 | o ) dir=$OPTARG 26 | output 27 | ;; 28 | \? ) echo "Usage: " 29 | echo " -l Gather Files Links"; 30 | echo " -o Make an Output Directory to put all things Together"; 31 | ;; 32 | : ) echo "Invalid Options $OPTARG require an argument"; 33 | ;; 34 | esac 35 | done 36 | shift $((OPTIND -1)) 37 | -------------------------------------------------------------------------------- /whileloop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Usage of Script: ./whileloop.sh count 4 | #example: ./whileloop.sh 20 5 | #By Altaf Shaikh 6 | 7 | valid=true 8 | count=1 9 | while [ $valid ] 10 | do 11 | echo $count 12 | if [ $count -eq $1 ]; 13 | then 14 | break 15 | fi 16 | ((count++)) 17 | done 18 | --------------------------------------------------------------------------------