chakolatemilk
chakolatemilk

Reputation: 883

Echo a command on screen

I would like to echo a command onto the screen. I'm making something of a tutorial for someone and I want to display the command that is going to be running when they press enter.

For example, I have this so far:

echo off

echo Tutorial

pause

echo .
echo .
echo This will show how to read the first line of a text file and place into another text file
echo .
echo .

pause

set /p texte=< test.txt
echo FOR %P IN (%texte%) DO(echo blah >> test2.txt)

pause

However, it won't work when it reaches the last echo, because I'm echoing a command rather than just a text. Is there a way to echo a command?

EDIT: When I try to run something like this, it'll say there is an error once it reaches that last echo command, it says I'm trying to run something following the echo command. But in reality, what I'm trying to do is show the command I'm going to be using on the next line or something along those lines.

This is just an example of what I'm doing, I'm sorry if the actual echo statement just doesn't make sense in general. I'm just wondering if there was a way to echo a command.

Upvotes: 0

Views: 427

Answers (3)

iCodeSometime
iCodeSometime

Reputation: 1643

> is a special symbol, so you need to escape it. The escape character in bash is the carat: ^ therefore ^>^> should fix that problem, however batch still interprets % differently. for that you need %%. This:

Echo FOR %%P IN (%%texte%%) DO(echo blah ^>^> test2.txt)

will output the command exactly as you want. Also if you add @ before your echo off it won't echo echo off at the beginning of your script.

Upvotes: 1

BDM
BDM

Reputation: 3900

Because no one has answered yet, I'm going to attempt this on my phone.

The reason its giving an error is because you need to escape some stuff.

Echo for ^%p in ^(^%texte^%^) do ^(echo Blah ^>^> test2.txt ^)

That took about 20 minutes so I better get at least an upvote.

Upvotes: 1

unxnut
unxnut

Reputation: 8839

In most of the shells, there is a debug mode to achieve what you want. For example, in Korn shell, you can type set -x to achieve this.

Upvotes: 1

Related Questions