'sed: can't read ../../build.gradle: No such file or directory

I am new to git and github. I am working on a project where I need to commit my changes to github repository in a specific branch. But I am getting the error

$ git commit

3.5.0.1
s/3.5.0.1/3.5.1.1/g
sed: can't read ../../build.gradle: No such file or directory

I have also attached the pre-commit file code here.

#!/bin/sh

## finding the exact line in the gradle file
#ORIGINAL_STRING=$(cat ../../build.gradle | grep -E '\d\.\d\.\d\.\d')
## extracting the exact parts but with " around
#TEMP_STRING=$(echo $ORIGINAL_STRING | grep -Eo '"(.*)"')
## the exact numbering scheme
#FINAL_VERSION=$(echo $TEMP_STRING | sed 's/"//g') # 3.5.0.1

#Extract APK version
v=$(cat build.gradle  | grep rtVersionName | awk '{print $1}')
FINAL_VERSION=$(echo ${v} | cut -d"\"" -f2)
echo ${FINAL_VERSION}

major=0
minor=0
build=0
assets=0

regex="([0-9]+).([0-9]+).([0-9]+).([0-9]+)"
if [[ $FINAL_VERSION =~ $regex ]]; then
 major="${BASH_REMATCH[1]}"
 minor="${BASH_REMATCH[2]}"
 build="${BASH_REMATCH[3]}"
 assets="${BASH_REMATCH[4]}"
fi

# increment the build number
build=$(echo $build + 1 | bc)
NEW_VERSION="${major}.${minor}.${build}.${assets}"


SED_ARGUMENT=$(echo "s/${FINAL_VERSION}/${NEW_VERSION}/g")
echo $SED_ARGUMENT

sed -i -e `printf $SED_ARGUMENT` ../../build.gradle

The error comes in the last line of this file basically. I am using windows. Things I tried:

sed -i -e `printf $SED_ARGUMENT` ../../build.gradle



sed -i ' ' -e `printf $SED_ARGUMENT` ../../build.gradle

I am unable to understand where am I actually doing wrong. Kindly help me out.



Solution 1:[1]

sed: can't read ../../build.gradle: No such file or directory

This one is rather simple. Your build.gradle file is not at ../../build.gradle.

The solution is to determine actual path to the build.gradle file relative to the script, and change the path in the script.

To debug this, do echo Current Directory: $PWD in the script to see what the actual working directory is, then you should be able to determine the correct path to use.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GreenSaguaro