Answer the question
In order to leave comments, you need to log in
Why doesn't exit 1 work everywhere in sh script code?
Hello!
There is a pre-commit hook script in sh for subversion. Among other things, the script must forbid committing files larger than a certain size. The fact is that even if the size ratio condition is met and the if-then path is followed, the script does not execute exit 1 and does not display the echo message .
With the help of different echo , it was found out that the script accurately receives and correctly interprets the values of all variables, and also makes a comparison. If you write some echo before the line
echo "File '$file' too large to commit" >&2and after exit 1 -- they will be executed.
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK="/usr/local/bin/svnlook"
maxsize=20000000 #ограничение на максимальный размер файла (не коммита целиком) в байтах
$SVNLOOK changed -t $TXN $REPOS | while read status file
do
&& continue # Skip Deletions
&& continue # Skip directories
size=$($SVNLOOK filesize -t $TXN $REPOS $file)
if [ $size -gt $maxsize ]
then
echo "File '$file' too large to commit" >&2
exit 1
fi
done
exit 0
Answer the question
In order to leave comments, you need to log in
What if something like that?
while read status file
do
&& continue # Skip Deletions
&& continue # Skip directories
size=$($SVNLOOK filesize -t $TXN $REPOS $file)
if [ $size -gt $maxsize ]
then
echo "File '$file' too large to commit" >&2
exit 1
fi
done < <($SVNLOOK changed -t $TXN $REPOS)
First of all, I would reverse the while loop so that it does not run in a subshell
AND output the result of the command to a file so that later I can analyze whether the contents are expected.
SVNRESULT=`$SVNLOOK changed -t $TXN $REPOS`
echo -e"`date '+%F %T'`\n${SVNRESULT}" >> ~/debug-svn.log
while read status file; do
....
done <<<"${SVNRESULT}"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question