简体   繁体   中英

Pre-commit hook permission denied inside script

I have following pre-commit hook:

#!/bin/bash

set -e

result=''

for file in $(find rest/src/main/groovy/ru/naumen/modules -name '*.groovy' | sort); do
    filename=basename "$file"
    result+=echo "${filename//.groovy/}",
done

result+='smpUtils'

sed -i -r "s|modules = .*|modules = $result|g" rest/smpsync.ini

git add rest/smpsync.ini

I'm getting Permission denied error on line 8

filename=basename "$file"

And I'm not able to determine the reason of it.

Hook itself has execution rights ( chmod +x .git/hooks/pre-commit )

Whole directories/files tree in ./rest/src/main/groovy/ru/naumen/modules has read/write rights and belongs to my user.

Try instead:

filename="$(basename "$file")"

In order to get the result of the command basename in your filename variable.

Issue #1 was as mentioned by @VonC in variable assignment

filename=basename "$file" -> filename=$(basename "$file")

Issue #2 was in line #9 (I just removed echo ):

result+=echo "${filename//.groovy/}", -> result+="${filename//.groovy/}",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM