I'm using a shell script in git bash to call sqlcmd to run some sql scripts. The script names are based on the git branch name, so the command is sqlcmd -E -S mySQLServer -d myDB "$branchsql"
It works fine from the command line, but I want to repeat it for several git branches, so I have a script that calls this script for a list of branches:
While read branch
do
. C:/sqlScript.sh $branch
done < "$1"
The file with the list of branches is passed in $1
What happens is that is reads the first branch from the list, but never moves on to the next one. It repeatedly executes sqlScript.sh with the same value in $branch.
If I change sqlScript to just echo $1, everything works as expected. When I call sqlcmd, the first branch only is passed. So why does sqlcmd mess things up ?
CodePudding user response:
Drop the leading dot, invoke C:/sqlScript.sh ...
rather than . C:/sqlScript.sh ...
. scripts.sh
is short for source script.sh
,: it will execute the commands listed in script.sh
in the current shell. If you have a command such as exit
it will exit the current shell.
A regular invocation will start a separate shell, which won't mess with your current one.
CodePudding user response:
Thanks, but executing either way has the same result. If I execute sqlcmd in the script I call, I get this effect of only reading the first line from the list of branches. If I just do say Git checkout and git pull, it works. If I add sqlcmd, it gets stuck on the first branch.