I have content= $(git diff --cached $line) in my bash script.

But when I execute it, bash throws error
gqqnbig MINGW64 /c/Website/Lender (master)
$ ./hook.sh
Admin/Xpress/BusinessAccountTypeRole_Edit.aspx
diff: unknown option -- git
diff: Try 'diff --help' for more information.
Why doesn't $(git diff --cached $line) work, and how to fix it?
It doesn't work because you put a space after the equals sign.
content= $(git diff --cached $line)
^
there
That space means Bash sets the environment variable content to the empty string for the command specified by the rest of the line, instead of setting the shell variable content to the result of running the command.
To fix it, remove the space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With