-1

It seems like a relatively simple bit of script that isn't working for me when I try to save a user input to a variable. Any ideas?

@echo off

echo changing to user directory...
cd %HOMEPATH%

echo checking if repo already exists...
if exist Service%%20and%%20Performance%%20Monitoring\ (

echo changing to local repo directory...
  cd Service%%20and%%20Performance%%20Monitoring
  echo pulling down any changes in the remote repo...
  git pull --rebase
  
  
  echo committing and pushing new changes to ADO...
  git add .
  set /p comment= Comments to go with this commit:
  echo your comment is %comment%
  PAUSE
  git commit -m "%comment%"
  git push
) else (

When I run the.bat this is what I get...

Comments to go with this commit: my  comment
your comment is

As you can see the variable is empty!?

PWNFUM
  • 19
  • 4
  • Please do not use `cd %HOMEPATH%`; it assumes that the code is running with a specific current directory, _(you have not defined one)_, probably ```C:\```, it should ideally be doublequoted too. Use ```CD /D "%HOMEDRIVE%%HOMEPATH%"```, or possibly ```CD /D "%USERPROFILE%"``` instead. – Compo Aug 26 '22 at 14:59

1 Answers1

0

Solved by adding:

SETLOCAL EnableDelayedExpansion

Into my IF block and using !comment! to reference the variable.

what an unusual problem to have!

PWNFUM
  • 19
  • 4