1

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.

2
  • filename=basename "$file" you need a $( ) but also can be done with P.E. filename=${file##*/}
    – Jetchisel
    Commented Feb 20, 2020 at 5:46
  • But that is not the only problem, try this site for validating shell scripts. shellcheck.net
    – Jetchisel
    Commented Feb 20, 2020 at 5:50

2 Answers 2

1

Try instead:

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

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

1

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/}",

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