-1

I need to use gitbash on MS-Windows with file folder names that contain an exclamation point as the first characters, like "!0-MyProjectFolder" (without the quotation marks. I use the exclamation point to sort Microsoft Windows files to the top, since Windows does not provide a way to index and force sort order of files and folders.

Gitbash keeps giving me error messages:

I've tried several syntaxes already:

$ cd "!0-Projects-WIP"
bash: !0: event not found

$ cd "\!0-Projects-WIP"
bash: \!0: event not found

$ cd !0-Projects-WIP
bash: !0: event not found

Be clear that I am NOT parsing a string like '/New.*desktop.*is/!d' in the StackOverflow posting at How to address error "bash: !d': event not found" in Bash command substitution

VNCServerAndDisplayNumber="$(echo "${VNCServerResponse}" \
    | sed '/New.*desktop.*is/!d' | awk -F" desktop is " '{print $2}')"

I am passing the directory name !0-Projects-WIP to GitBash, so that I can change into the directory named !0-Projects-WIP. I am not intending to do double-quoting or history expansion. If the exclamation point in the folder name appears to be a history expansion directive, then that is not the intended result. The ! must be escaped in my case so that it is read correctly as part of the folder name, and the shell command "cd" interprets it as a string.

I realize now that !0-Projects-WIP is probably a bad name to a Unix shell parser because it directs the command line parser to do something that was not my intention, but for the MS-Windows command line shell there is no confusion.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Rich Lysakowski PhD
  • 2,702
  • 31
  • 44
  • Possible duplicate of [How to address error "bash: !d': event not found" in Bash command substitution](https://stackoverflow.com/questions/25003162/how-to-address-error-bash-d-event-not-found-in-bash-command-substitution) – matt Apr 06 '19 at 01:37
  • The intention of my command is different from what the other poster in https://stackoverflow.com/questions/25003162/how-to-address-error-bash-d-event-not-found-in-bash-command-substitution was trying to do. The solution is different in my case too. – Rich Lysakowski PhD Apr 07 '19 at 05:21
  • Possible duplicate of [echo "#!" fails -- "event not found"](https://stackoverflow.com/questions/11816122/echo-fails-event-not-found) – tripleee Apr 07 '19 at 05:25

1 Answers1

1

I got it to work with just a single escape character in front of the string:

$ cd \!0-Projects-WIP

rlysa@domainname MINGW64 /c/users/rlysak01/desktop/!0-Projects-WIP (master)
$

Simple solution. No quotation marks needed on the folder name string.

Rich Lysakowski PhD
  • 2,702
  • 31
  • 44