After a bit of googling and searching here, couldn't find the answer to this silly question!
For a structure like this...
dirZero
|---dirOne
|---|---myProgram.exe
How do I run "myProgram" if my current directory is dirZero? I.E.,
C:\dirZero> dirOne/myProgram.exe
...which obviously doesn't work.
You should use a backslash \, instead of forward slash. /
C:\dirZero> dirOne\myProgram.exe
Or, wrap it with double quotes "
C:\dirZero> "dirOne/myProgram.exe"
Use a backslash instead
C:\dirZero> dirOne\myProgram.exe
probably u should just simple use
cd C:\dirZero\dirOne
C:\dirZero\dirOne> myProgram.exe
Related
I have a variable with a path, like this:
SET "somevar=D:\tree\path\nonsens\oink.txt"
And I have a file, where somethink like this is written
VAR=moresonsense
Now I want to replace the word morenonsense to D:\tree\path\nonsens\oink.txt. This should be the result
VAR=D:\tree\path\nonsens\oink.txt
For this, I am using the tool sed for windows. But using sed in windows gives me the following:
VAR=D: ree/path/nonsens/oink.txt
The spaces between the colon and ree is a tab. I thought, I could fix it with the following line before calling sed:
SET "somevar=%somevar:\\=\\\\%"
But no, this line is not working. So I have some questions:
Is there a possibility, to prevent sed from changing \t to a tab and prevent changing two backslashed \ to a slash /?
Is there another easy way to replace a string with another string within a file with BATCH?
Does someone has another idea how to resolve this problem?
You should not \-escape the \ instances in the variable expansion; use the following:
SET "somevar=%somevar:\=\\%"
I don't know whether that solves all your problems, but SET "somevar=%somevar:\\=\\\\%" definitely does not work as intended, because it'll only match two consecutive \ chars in the input, resulting in a no-op with your input.
I noticed that cmd seems to accept some characters at the ends of commands. for example all of the following function correctly:
cls.
cls;
cls(
cls\
cls+
cls=
cls\"whatever"
cls\$
cls\#
and these do not:
cls'
cls$
cls)
cls-
cls#
cls\/
Does anybody know why this happens?
Thanks in advance.
It depends on the batch parser.
;,= are general batch delimiters, so you can append/prepend them to the most commands without effect.
;,,= ,=; echo hello
;,cls,;,,
The . dot can be appended to the most commands, as the parser will try to find a file named cls (without extension) cls.exe cls.bat, and when nothing is found then it takes the internal command.
The opening bracket is also a special charcter that the parser removes without error.
The \ backslash is used as path delimiter, so sometimes it works but sometimes you could change even the command.
cls\..\..\..\windows\system32\calc.exe
I have a make file and I am trying to use it to copy files to a directory. The path of the directory is stored in an environment variable. The problem is when I run make the C:\Data from the environment variable is interpreted as C:Data. How do I stop this being intrepreted as an escape character?
copyData : buildData
cp Release/*.tbl $(DATA)/index
results in:
cp Release/*.tbl C:\Data/index
cp: `C:Data/index': specified destination directory does not exist
Try `cp --help' for more information.
Actually, using forward slashes is the best, and correct, solution. Windows utilities always support forward slashes so it works, and trying to remember to always quote pathnames to avoid issues with backslashes is a major hassle.
In this case the first thing to note is that the problem is not a problem with make. make is passing the right content to the shell; it's the shell which is parsing the backslash as an escape character.
As I said above the right answer is to use forward slashes BUT if you want to allow people to use backslashes you'll have to go through your makefile and quote all arguments where a backslash might appear. For example:
copyData : buildData
cp Release/*.tbl '$(DATA)'/index
will fix your immediate problem.
If you have just a couple of these variables you could also do something like:
QDATA = '$(DATA)'
then remember to use $(QDATA) where you wanted the quoted value:
copyData : buildData
cp Release/*.tbl $(QDATA)/index
PS. Use forward slashes!! :-)
I am trying to use wget with a url that includes a "#" sign. No matter what I do to escape the character, it doesn't work. I've used \, ', and ". But none of them work. Does any one have any suggestions?
Thank you!
Send it as %23 if you really mean for it to have a hash. If you're trying to send a fragment, don't bother since the server won't care about it regardless.
maybe put uri around'' ? I believe it works
Are you quoting the url? It shouldn't be a problem if you are.
My guess is you're doing something like:
wget http://foo.com/#!/blah
Instead of:
wget "http://foo.com/#!/blah"
# is the shell script comment character.
I am trying to do the following in ksh but keep getting cannot stat message for the cp command:
JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation
SMOKE_JMX_LOCATION=$JMX_ROOT/"Smoke Set"/*.*
cp $SMOKE_JMX_LOCATION /var/tmp/tempor
Any ideas, have tried putting quotes around the various variables but with no luck. Think its something to do with the spaces in "Smoke Set" but don't how how to work it.
Many thanks.
JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation
SMOKE_JMX_LOCATION="$(echo $JMX_ROOT/"Smoke Set"/*.*)"
cp "$SMOKE_JMX_LOCATION" /var/tmp/tempor
JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation
SMOKE_JMX_LOCATION=$JMX_ROOT/"Smoke\ Set"/*.*
cp $SMOKE_JMX_LOCATION /var/tmp/tempor
Does this solve your problem? Adding a \ before the space.
try escaping the space with a backslash
SMOKE_JMX_LOCATION=$JMX_ROOT/Smoke\ Set/*.*