Commands in PowerShell are almost like Bash, but the dot notation expansion is creating a lot of work for me. Currently I have to wrap a lot of command parameters in quotes:
.\mvnw.cmd -Dmaven.repo.local=.m2/repository deploy:deploy-file -Durl=http://zippo:8081/repository/grinch/ -DrepositoryId=nexus -DgroupId=com.zippo -DartifactId=test -Dversion=1.0 -Dpackaging=jar -Dfile=test-1.0.jar
becomes
.\mvnw.cmd -D"maven.repo.local"=".m2/repository" deploy:deploy-file -Durl=http://zippo:8081/repository/grinch/ -DrepositoryId=nexus -DgroupId="com.zippo" -DartifactId=test -Dversion="1.0" -Dpackaging=jar -Dfile="test-1.0.jar"
How can I disable dot notation, or override the dot operator, replace it with something else, etc.?
How can I disable dot notation?
The problem isn't dot notation, it is a bug in how PowerShell parses arguments to be passed to external programs:
-foo.bar
is unexpectedly broken into two arguments, -foo
and .bar
- see GitHub issue #6291 (accidental duplicate: GitHub issue #15541); this is but one among several related bugs, present up to at least PowerShell 7.3.6.Escaping or quoting is indeed needed to work around this problem, but you can simplify it by `
-escaping the initial -
of each affected argument or by enclosing each as a whole in '...'
(or "..."
, if you need string interpolation):
# `-escape the initial - of all affected arguments.
.\mvnw.cmd `-Dmaven.repo.local=.m2/repository deploy:deploy-file -Durl=http://zippo:8081/repository/grinch/ -DrepositoryId=nexus `-DgroupId=com.zippo -DartifactId=test `-Dversion=1.0 -Dpackaging=jar `-Dfile=test-1.0.jar
# Alternative: Quote the affected arguments.
.\mvnw.cmd '-Dmaven.repo.local=.m2/repository' deploy:deploy-file -Durl=http://zippo:8081/repository/grinch/ -DrepositoryId=nexus '-DgroupId=com.zippo' -DartifactId=test '-Dversion=1.0' -Dpackaging=jar '-Dfile=test-1.0.jar'
If you don't want to have to think about which specific arguments may be affected, quote them all, which - combined with the fact that you can pass arguments as an array of strings, using @(...)
, the array-subexpression operator - can be used to make a long command more readable, by spreading it across multiple lines:
.\mvnw.cmd @(
'-Dmaven.repo.local=.m2/repository'
'deploy:deploy-file'
'-Durl=http://zippo:8081/repository/grinch/'
'-DrepositoryId=nexus'
'-DgroupId=com.zippo'
'-DartifactId=test'
'-Dversion=1.0'
'-Dpackaging=jar'
'-Dfile=test-1.0.jar'
)
Alternatives:
You can use --%
, the stop-parsing token, which obviates the need for quoting, but note its many limitations, notably the inability to (directly) incorporate PowerShell variables and expressions into the command - see this answer for details.
# --% passes the remainder of the command line as-is to the target program
.\mvnw.cmd --% -Dmaven.repo.local=.m2/repository deploy:deploy-file -Durl=http://zippo:8081/repository/grinch/ -DrepositoryId=nexus -DgroupId=com.zippo -DartifactId=test -Dversion=1.0 -Dpackaging=jar -Dfile=test-1.0.jar
You can call via cmd /c
, in which case you can quote your entire command line, which avoids the parsing bug (though note that the command specified in the string must then satisfy cmd.exe
's syntax rules; they can differ from PowerShell's, albeit not in this case):
cmd /c '.\mvnw.cmd -Dmaven.repo.local=.m2/repository deploy:deploy-file -Durl=http://zippo:8081/repository/grinch/ -DrepositoryId=nexus -DgroupId=com.zippo -DartifactId=test -Dversion=1.0 -Dpackaging=jar -Dfile=test-1.0.jar'
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