Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to write an SVN post-commit hook and, strangely, am getting hung up on what should be the easiest part.

The Script:

#!/usr/bin/sh
set REPO="$1"
set REV="$2"

set SVNBIN="/opt/CollabNet_Subversion/bin/"
set SSHBIN="/usr/bin/ssh"

set HOST="staging.domain.net"
set timeout=30
set USERNAME="svn-usr"

set E_NO_CONNECT=2
set E_WRONG_PASS=3
set E_UNKOWN=25

set CHANGED=`"$SVNBIN"svnlook changed --revision $REV $REPOS`
echo "Here are changes: $CHANGED" >> /var/svn/repos/www/logs/testing
echo "Command: $0; Repo: $REPO; Rev: $REV; Total: $#" >> /var/svn/repos/www/logs/testing
set PROJECT ""

Yet when I call it, it doesn't seem to be seeing the arguments I pass to it:

/var/svn/repos/www/logs> sudo ../hooks/post-commit /var/svn/repos/www 33
svnlook: missing argument: --revision
Type 'svnlook help' for usage.
/var/svn/repos/www/logs> cat testing
Here are changes:
Command: ../hooks/post-commit; Repo: ; Rev: ; Total: 1

This is on a Solaris 10 SPARC box.

I'm a bit of a script newbie, but shouldn't this be really easy??

share|improve this question
    
csh uses the set keyword in that way. sh doesn't. –  Dennis Williamson Apr 19 '10 at 16:04

3 Answers 3

up vote 5 down vote accepted

set doesn't do what you think it does: it modifies the positional arguments $1, $2, ... $@, etc. It doesn't assign variables.

set REPO="$1"
set REV="$2"

should be:

REPO="$1"
REV="$2"

(etc)

share|improve this answer
    
Ah, that explains it. Why does $# still only return 1 though? –  Nate Wagar Apr 19 '10 at 14:46
1  
cuz you're accessing $# after modifying the positional parameters using 'set'. –  Shizzmo Apr 19 '10 at 16:07
    
@Nate Wagar: Because $# is also defined in terms of the positional parameters. Read the BASH manual page, and read especially the parts about Positional Parameters and Special Parameters. –  geocar Apr 19 '10 at 19:40

I'm not sure why you have all those set commands, remove them and see if works?

share|improve this answer
    
Because "I'm a bit of a script newbie" :P –  Nate Wagar Apr 19 '10 at 14:46
REPO="$1"
REV="$2"

SVNBIN="/opt/CollabNet_Subversion/bin/"
SSHBIN="/usr/bin/ssh"

HOST="staging.domain.net"
timeout=30
USERNAME="svn-usr"

E_NO_CONNECT=2
E_WRONG_PASS=3
E_UNKOWN=25

CHANGED=`"$SVNBIN"svnlook changed --revision $REV $REPOS`
.....
PROJECT=""
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.