I've written a short script which needs to find some text using regex.
I'm incrementing a counter inside a while loop, and this counter is part of another command. Unfortunately this command is always running with the initial counter.
Here a snippet from my code:
COUNTER=1
LAST_COMMIT=`git log remotes/origin/devel --pretty=oneline --pretty=format:%s | head -${COUNTER}`
JIRA_ID=`echo $LAST_COMMIT | grep -o -P '[A-Z]{2,}-\d+' | xargs`
while [[ ! -z "$JIRA_ID" && $COUNTER -lt "5" ]]; do
echo "This is the current counter: $COUNTER"
echo "This is the last commit $LAST_COMMIT"
COUNTER=$[COUNTER+1]
done
echo "this is the counter outside the loop $COUNTER"
$COUNTER. If you need to run it with a different value then you need to run it again. NeitherLAST_COMMITnorJIRA_IDever change once set. Also| xargsis likely pointless there as it is just/bin/echo.LAST_COMMITvalue you need to run that command. Not just once before the loop. Same thing for every time you want to get a newJIRA_IDvalue (from a newLAST_COMMITvalue).git loghow many entries to output directly you don't needheadfor that. And this is going to get you increasingly many lines of output fromgit logeach time yourCOUNTERincrements and I don't think that's what you want. (Also I think--pretty=formatis overriding--pretty=onelineso you probably don't need both.)