Jump to content

Echo command in batch


Royalaid
 Share

Recommended Posts

Hey guys was just wondering if there is a way to make a batch file echo something exactly as I type it, for example

echo set name=c:/%num%.bat >> %name% 

I get the output of

set name=c:/1.bat

I want it to put that exact text (set name=c:/%num%.bat) in the file not what %num% is equal to, any help is much appreciated and thanks in advance.

Link to comment
Share on other sites

you must be doing something wrong. What neXusst said is correct the ^ character will allow you to use special characters.

open a command prompt and type the following...

echo set name=c:/^%num^%.bat ^>^> ^%name^%

your outout should be...

set name=c:/%num%.bat >> %name%

Link to comment
Share on other sites

Make sure that you have @echo on at the top of the script. Then you need to put an extra % in front of each % and a ^ (caret) in front of each >. These are called "escape characters".

So... your script will look like this:

@echo on

echo set name=c:/%%num%%.bat ^>^> %%name%%

pause

Link to comment
Share on other sites

The @ character turns off echoing of the command itself, so you only see the output of the command. You can affect the entire batch file by putting a "@echo off" at the beginning of the file.

An example of a command in a batch file without disabling echoing:

echo Hello World!

The result:

echo Hello World!

Hello World!

An example of turning off echoing for an entire batch file:

@echo off

echo Hello World!

The result:

Hello World!

If you want to disable echoing for only one command, use this:

@echo Hello World!

---

Using "@echo off" is very standard for batch files, and you will almost never see one without it.

neXussT

Link to comment
Share on other sites

Adding the extra percent helped fix the echo problem, and now I have the file actually working, all I need to do is make it map the C drive is there anyway that I can get the dir command to show me just files and would get the out from that be as simple as adding >> filelist.txt to the end?

Link to comment
Share on other sites

Type "DIR /?" for information on the DIR commands paramaters

If you want a list of files in the current directory without listing the directory, type this:

DIR /a-d

If you want to get rid of the file information, type this:

DIR /b/a-d

If you want a list of all the files in the current directory and subdirectories without listing the directories, type this:

DIR /s/b/a-d

You can learn a lot by typing the following commands:

SET /?

DIR /?

FOR /?

HELP

neXussT

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...