I must develop some shell scripts that call some repetitive code that execute sql commands to database.What is the best method to make these, with functions in an external shell script, with external shell script with these sql commands or why?
best method to call repetitive code with sql code
shell script
Just write it as a function and include it in your script.For example, write a util or function script. lets call it util.sh and it has just functions in it:#!/bin/shsqlCall () {   echo sqlCall(), \$1:[${1}]}repeatedFunction () {   echo repeated x:[${1}] times   RETURNVAR=`date`}And then script1.sh and script2.sh can include util.sh like so:#!/bin/sh## script 1 - includes util.sh, calls only sqlCall# Include the functions. /path/to/util.shvar=s1 s2 s3for s in $vardo    sqlCall $sdoneAnd this is script2.sh#!/bin/sh## script 2 - includes util.sh, calls only repeatedFunction# Include the functions. /path/to/util.shi=0while [ $i -lt 4 ]do    repeatedFunction $i    i=$(($i + 1))doneecho Date: ${RETURNVAR}And the result for this would be:sh ./script1.shsqlCall(), $1:[s1]sqlCall(), $1:[s2]sqlCall(), $1:[s3]sh ./script2.shrepeated x:[0] timesrepeated x:[1] timesrepeated x:[2] timesrepeated x:[3] timesDate: Fri Jun 16 21:15:24 AEST 2017