When the code
SRC=$(cd $(dirname "$0"); pwd)
is executed inside a Bash script on a system that has Git for Windows installed in c:\program files\Git, the SRC will get the value /c/program.
How do I make this work? I need to get the path to where the script is and use that to include other scripts with a relative path. In my case the next line is: source "${SRC}/common/common.sh"
The script is in c:\program files\Git\usr\bin so I can use git <command-name> and extend Git with some useful hand-made commands for feature branch workflow with rebase and submodules.
The source code is at https://github.com/jlovs/git-scripts if anyone want to help out.
You need to double-quote the argument of the cd command.
SRC=$(cd "$(dirname "$0")"; pwd)
The command substitution $(dirname "$0") expands to a path containing a space. The following cd command gets two arguments while you want to pass just one, with a space inside.
You don’t need to worry about the quotes around $0 inside another pair of quotes since the $() command substitution starts a new quoting context.
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