Command output for conditionals appears to fail for Git Bash
matthew-brett opened this issue · comments
Please forgive me if I misunderstood the syntax, but I have a clause in my install file for Windows installs:
~/Documents/WindowsPowerShell/Profile.ps1 :
path: Profile.ps1
if: '[ $(command -v powershell) ]'
This always skips. Investigating, this version of the if
clause does not skip:
if: '[ -d "/c/Windows/System32" ]'
nor does this:
if '[ `echo` ]'
but this does:
if: '[ `echo yes` ]'
On the other hand, if I run this from the Git Bash shell, I get the expected "is true" output:
$ if [ `echo yes` ]; then echo 'is true'; fi
Is there something specific going on in Git Bash and the conditional clauses here?
You're using bash conditional syntax, which may not be appropriate on Windows.
Dotbot runs the if
block using Python's subprocess
module, which doesn't guarantee that you'll be running in whatever shell you started in. For example, if you're running the install script in Powershell, the if
block will run in the equivalent of cmd.exe
.
One solution may be to use Python to check your paths. Something similar to this may work:
if: python -c "import pathlib, sys; sys.exit(0) if pathlib.Path(r'C:\Windows\System32').is_dir() else sys.exit(1)"
@matthew-brett closing due to inactivity. If this is not resolved, feel free to re-open.