Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the echo command works in batch programming

I'm have started to learn batch programming to go a little more deeper in the Windows Machines. In Internet I have seen some commands with echo like "@echo off" or "on" and also this: "echo." but I don't know what are they doing. If anyone can explain me the functions of the echo command, please answer me.

like image 242
BAR Software Avatar asked Jun 16 '17 11:06

BAR Software


People also ask

What does echo do in batch?

In computing, echo is a command that outputs the strings that are passed to it as arguments. It is a command available in various operating system shells and typically used in shell scripts and batch files to output status text to the screen or a computer file, or as a source part of a pipeline.

How does echo work in CMD?

The echo command repeats typed text back to the screen and can send text to a peripheral on the computer, such as a COM port.

What is the function of the echo statement?

The echo command is a built-in Linux feature that prints out arguments as the standard output. echo is commonly used to display text strings or command results as messages.


2 Answers

The ECHO command in Windows CMD is used to print out text to the screen, display the actual setting of the Command-line which means when you do:

@echo off

The "C:\Users[User]" line before your command input will disappear. You can restore it with:

@echo on

Here all functions of ECHO explained:

  • @echo [on/off] (to set the command-line settings)

  • echo [text] (to print text to the screen)

  • echo. (to print an empty line to the screen)

  • echo (displays the current setting of the command-line)

  • echo /? (displays help for the command ECHO)

I hope I was able to help you.

like image 182
Antonio Gschossmann Avatar answered Oct 24 '22 16:10

Antonio Gschossmann


By default, every command executed in a batch file is also echoed to the output - not just the output of the command, but the command itself.

The echo command has three modes:

  1. When called with some arguments AFTER a space, it will output the arguments.
  2. When called as echo. (no space) it will output just a blank line.
  3. When called with just the arguments on or off, it controls the behaviour of printing the commands as they execute.*

So, the echo off command turns off the output at the start of the batch file. However, that command itself is still echoed before it has a chance to turn off the echoing. The @ symbol has the effect of turning off the output for only the current command.

Combining the two, the @echo off at the start of a batch file turns off the echoing without itself being echoed.

(* I'm not sure exactly how to output the text "on" or "off", but I suspect that using quotes around the text will change the behaviour.)

like image 43
Harun Avatar answered Oct 24 '22 17:10

Harun