1

I have made a batch file in Windows. The content in that file is like this

test.bat

echo %1

Now when I send an argument from command line like this

test.bat "hello"

then it outputs always %1. It should be hello.

What I am doing wrong?

2 Answers 2

2

Perhaps you are using power-shell. you need to use the following in your bat file:

echo $1

Here is Converting DOS Batch Files to Shell Scripts

 http://tldp.org/LDP/abs/html/dosbatch.html
Sign up to request clarification or add additional context in comments.

Comments

2

This is really odd - something in your assumptions about what is in the file is not correct. Here is the output from my pc doing exactly what you describe:

C:\windows\system32>copy con test.bat
echo %1
^Z
        1 file(s) copied.

C:\windows\system32>test.bat hello

C:\windows\system32>echo hello
hello

I suspect the file has something different in than what you describe

4 Comments

I am doing right but I can get it that why code is not working perfect on my PC.
Is that all test.bat contains?
please post more detail: an actual dump of the file and actual output from a run like the one above
@user230910 good catch. Actually I was testing that file using git but when I try this using cmd it works fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.