Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a common git "post-receive" script for several projects, and it needs to perform different actions if an /app/ or /public/ folder exists in the root.


FOLDERS=`git ls-tree -d --name-only -z master`;

I can see the directory listing, and I would like to use the RegExp support in bash to run something like:

if [[ "$FOLDERS" =~ app ]]; then

But that won't work if there was something like an "app lication" folder... I specified the "-z" option in the git "ls-tree" command so I could use the \0 (null) character as a separator, but not sure how to test for that in the bash RegExp.

Likewise I know there is support for specifying a particular path in the ls-tree command, and could then pipe that to "wc -l", but I'd have thought it was quicker to get a full directory listing of the root (not recursive) then test for the 2 (or more) folders with the returned output.

Possibly related to:

share|improve this question
up vote 0 down vote accepted

It looks like the NULL character is lost (or ignored), as if the listing includes "app" and "httpd", it will match the string "apphttpd".

So I've gone with calling "git ls-tree" multiple times for now to see if each individual file exists.

if [ `git ls-tree -d --name-only master "$F" | wc -l` -eq 1 ]; then
share|improve this answer

Your Answer


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.